Class: Exo::ItemPresenter

Inherits:
Object
  • Object
show all
Defined in:
app/presenters/exo/item_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(item, decorated_resource = nil) ⇒ ItemPresenter

Returns a new instance of ItemPresenter.



5
6
7
8
# File 'app/presenters/exo/item_presenter.rb', line 5

def initialize item, decorated_resource=nil
  self.item = item
  self.resource = decorated_resource || ResourcePresenter.new(item.resource)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *params, &block) ⇒ Object



10
11
12
13
14
15
16
17
# File 'app/presenters/exo/item_presenter.rb', line 10

def method_missing meth, *params, &block 
  _field = resource.meta_field(meth)
  if _field
    item.value_for _field
  else
    item.send meth, *params, &block
  end
end

Instance Attribute Details

#itemObject

Returns the value of attribute item.



3
4
5
# File 'app/presenters/exo/item_presenter.rb', line 3

def item
  @item
end

#resourceObject

Returns the value of attribute resource.



3
4
5
# File 'app/presenters/exo/item_presenter.rb', line 3

def resource
  @resource
end