Class: ModestPresenters::ModestPresenter
- Inherits:
-
Object
- Object
- ModestPresenters::ModestPresenter
- Defined in:
- lib/modest_presenter.rb
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#initialize(model, context, args = {}) ⇒ ModestPresenter
constructor
A new instance of ModestPresenter.
- #method_missing(*args, &block) ⇒ Object
- #present(&block) ⇒ Object
Constructor Details
#initialize(model, context, args = {}) ⇒ ModestPresenter
Returns a new instance of ModestPresenter.
5 6 7 |
# File 'lib/modest_presenter.rb', line 5 def initialize(model, context, args = {}) @model, @context = model, context end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(*args, &block) ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/modest_presenter.rb', line 9 def method_missing(*args, &block) target = if model.respond_to?(args.first) model else context end target.send(*args, &block) end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/modest_presenter.rb', line 3 def context @context end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
3 4 5 |
# File 'lib/modest_presenter.rb', line 3 def model @model end |
Instance Method Details
#present(&block) ⇒ Object
19 20 21 |
# File 'lib/modest_presenter.rb', line 19 def present(&block) instance_eval(&block) end |