Class: LittleDecorator
- Inherits:
-
Object
- Object
- LittleDecorator
- Defined in:
- lib/little_decorator.rb,
lib/little_decorator/helper.rb
Defined Under Namespace
Modules: Helper
Instance Attribute Summary collapse
-
#record ⇒ Object
(also: #model)
readonly
Returns the value of attribute record.
-
#view ⇒ Object
readonly
Returns the value of attribute view.
Instance Method Summary collapse
-
#initialize(record, view = nil) ⇒ LittleDecorator
constructor
A new instance of LittleDecorator.
- #method_missing(method_name, *args, &block) ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
Constructor Details
#initialize(record, view = nil) ⇒ LittleDecorator
Returns a new instance of LittleDecorator.
11 12 13 |
# File 'lib/little_decorator.rb', line 11 def initialize(record, view=nil) @record, @view = record, view end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/little_decorator.rb', line 16 def method_missing(method_name, *args, &block) [record, view].each do |item| return item.public_send(method_name, *args, &block) if item.respond_to?(method_name) end super end |
Instance Attribute Details
#record ⇒ Object (readonly) Also known as: model
Returns the value of attribute record.
8 9 10 |
# File 'lib/little_decorator.rb', line 8 def record @record end |
#view ⇒ Object (readonly)
Returns the value of attribute view.
8 9 10 |
# File 'lib/little_decorator.rb', line 8 def view @view end |
Instance Method Details
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
23 24 25 |
# File 'lib/little_decorator.rb', line 23 def respond_to_missing?(method_name, include_private=false) [record, view].any? { |item| item.respond_to?(method_name, include_private) } end |