Class: ModestPresenters::ModestPresenter

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

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#contextObject (readonly)

Returns the value of attribute context.



3
4
5
# File 'lib/modest_presenter.rb', line 3

def context
  @context
end

#modelObject (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