Class: Webmate::Decorators::Base
- Inherits:
-
Object
- Object
- Webmate::Decorators::Base
- Defined in:
- lib/webmate/decorators/base.rb
Instance Attribute Summary collapse
-
#entity ⇒ Object
readonly
Returns the value of attribute entity.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(entity, options = {}) ⇒ Base
constructor
A new instance of Base.
- #method_missing(method, *args, &block) ⇒ Object
Constructor Details
#initialize(entity, options = {}) ⇒ Base
Returns a new instance of Base.
5 6 7 |
# File 'lib/webmate/decorators/base.rb', line 5 def initialize(entity, = {}) @entity, @options = entity, end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/webmate/decorators/base.rb', line 23 def method_missing(method, *args, &block) if entity.respond_to?(method) self.class.send :define_method, method do |*args, &blokk| entity.send method, *args, &blokk end send method, *args, &block else super end rescue NoMethodError => no_method_error super if no_method_error.name == method raise no_method_error end |
Instance Attribute Details
#entity ⇒ Object (readonly)
Returns the value of attribute entity.
3 4 5 |
# File 'lib/webmate/decorators/base.rb', line 3 def entity @entity end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/webmate/decorators/base.rb', line 3 def @options end |
Class Method Details
.decorate(entity_or_collection, options = {}) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/webmate/decorators/base.rb', line 10 def decorate(entity_or_collection, = {}) if entity_or_collection.respond_to?(:map) entity_or_collection.map { |e| self.decorate(e, ) } else self.new(entity_or_collection, ) end end |
Instance Method Details
#id ⇒ Object
19 20 21 |
# File 'lib/webmate/decorators/base.rb', line 19 def id entity.id.to_s end |