Class: Decorator

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

Direct Known Subclasses

Contract

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(klass, method) ⇒ Decorator

Returns a new instance of Decorator.



118
119
120
# File 'lib/decorators.rb', line 118

def initialize(klass, method)
  @method = method
end

Class Attribute Details

.decoratorsObject

Returns the value of attribute decorators.



100
101
102
# File 'lib/decorators.rb', line 100

def decorators
  @decorators
end

Class Method Details

.inherited(klass) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/decorators.rb', line 102

def self.inherited(klass)
  name = klass.name.gsub(/^./) {|m| m.downcase}

  return if name =~ /^[^A-Za-z_]/ || name =~ /[^0-9A-Za-z_]/

  # the file and line parameters set the text for error messages
  # make a new method that is the name of your decorator.
  # that method accepts random args and a block.
  # inside, `decorate` is called with those params.
  MethodDecorators.module_eval <<-ruby_eval, __FILE__, __LINE__ + 1
    def #{klass}(*args, &blk)
      decorate(#{klass}, *args, &blk)
    end
  ruby_eval
end