Class: Contracts::Decorator
- Inherits:
-
Object
- Object
- Contracts::Decorator
- Defined in:
- lib/contracts/decorators.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.decorators ⇒ Object
Returns the value of attribute decorators.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(klass, method) ⇒ Decorator
constructor
A new instance of Decorator.
Constructor Details
#initialize(klass, method) ⇒ Decorator
Returns a new instance of Decorator.
207 208 209 |
# File 'lib/contracts/decorators.rb', line 207 def initialize(klass, method) @method = method end |
Class Attribute Details
.decorators ⇒ Object
Returns the value of attribute decorators.
189 190 191 |
# File 'lib/contracts/decorators.rb', line 189 def decorators @decorators end |
Class Method Details
.inherited(klass) ⇒ Object
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/contracts/decorators.rb', line 191 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 |