Skip to content

Instantly share code, notes, and snippets.

@Systho
Last active March 28, 2017 09:33
Show Gist options
  • Save Systho/6175d7bf924aef82df05 to your computer and use it in GitHub Desktop.
Save Systho/6175d7bf924aef82df05 to your computer and use it in GitHub Desktop.
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
unmemoized_method = Memoist.unmemoized_method_for(method_name)
return if method_defined?(unmemoized_method) # already memoized
return if caller.first =~ /memoist\.rb/ # do not memoize proxy method created by memoist
new_method = instance_method(method_name)
return if new_method.parameters.map(&:first).any?{|param_type| param_type == :block }
memoize(method_name)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment