Skip to content

Commit

Permalink
memoize for #decorate
Browse files Browse the repository at this point in the history
  • Loading branch information
sonots committed Sep 2, 2015
1 parent 21db558 commit a634d3e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/sinatra/decorator/decoratable.rb
Expand Up @@ -2,14 +2,15 @@ module Sinatra
module Decorator
module Decoratable
def decorate(options = {})
return @decorator if @decorator

klass = options[:as]
klass_name = "#{self.class}Decorator"
klass = klass_name.constantize if klass.nil?
decorator = klass.new(self, context: self)

yield decorator if block_given?
decorator
@decorator = decorator
end
end # Decoratable
end # Decorator
Expand Down

0 comments on commit a634d3e

Please sign in to comment.