Skip to content

Instantly share code, notes, and snippets.

View error_resolver.md

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.

@Systho
Systho / routes.rb
Last active Mar 28, 2017
routing concern on collection
View routes.rb
Rails.application.routes.draw do
concern :archivable do
scope module: parent_resource.plural do
resources :archiving, only: [:create, :destroy]
end
end
View application_decorator.rb
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
@Systho
Systho / podium.rb
Created Jun 12, 2015
Podium class to handle ranking, might be useful in the future
View podium.rb
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