Class: MiniDecorator

Inherits:
Module
  • Object
show all
Defined in:
lib/mini_decorator.rb

Instance Method Summary collapse

Constructor Details

#initialize(decorator) ⇒ MiniDecorator

Returns a new instance of MiniDecorator.



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/mini_decorator.rb', line 2

def initialize(decorator)
  define_method(:decorate) do |property|
    if decorator.respond_to? property
      decorator.public_send(property, self)
    elsif self.respond_to? property
      self.public_send(property)
    else
      raise NoMethodError.new "No decorator or object method found for property: #{property}"
    end
  end
end