This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Rails.application.routes.draw do | |
concern :archivable do | |
scope module: parent_resource.plural do | |
resources :archiving, only: [:create, :destroy] | |
end | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |