Skip to content

Instantly share code, notes, and snippets.

@Systho
Systho / podium.rb
Created June 12, 2015 07:10
Podium class to handle ranking, might be useful in the future
class Podium
def initialize(results)
@results = results
end
def rank_for(key)
score = results[key]
return 0 if score.nil?
index = reverse_results_hash.keys.index(score)
(0...index).to_a.sum{|prev_index| ranked_at(prev_index ).size } + 1
@Systho
Systho / routes.rb
Last active March 28, 2017 09:31
routing concern on collection
Rails.application.routes.draw do
concern :archivable do
scope module: parent_resource.plural do
resources :archiving, only: [:create, :destroy]
end
end
@Systho
Systho / application_decorator.rb
Last active March 28, 2017 09:33
Usual Draper Setup
class ApplicationDecorator < Draper::Decorator
extend Memoist
delegate_all
def method_added(method_name)
super
return if [:[], :initialize, :new].include?(method_name) # those method cannot be memoized
return if respond_to?(:object_class?) && object_class? && (method_name.to_s == object_class.name.underscore) # do not memoize object alias

Error Resolver

The error resolver process is triggered when an erroneous Imports::Line is updated with a group of resolved_attributes.

The resolved_attributes contain values which should have been computed by the parser, but the parser was unable to compute these values and produced an Imports::Error instead.

The interface will allow the user to resolve one or multiple attributes related to a common Imports::Line, the Error Resolver will treat those resolved_attributes separately.