Class: ExportTo::Presenter

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

Constant Summary collapse

NoAttributeError =
Class.new(NoMethodError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model, relation = nil, x, y) ⇒ Presenter

Returns a new instance of Presenter.



6
7
8
9
# File 'lib/export_to/presenter.rb', line 6

def initialize(model, relation=nil, x, y)
  self.model, self.relation = model, relation
  self.x, self.y = x, y
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/export_to/presenter.rb', line 15

def method_missing(m, *args, &block)
  obj = relation.respond_to?(m) ? relation : model
  if block_given?
    obj.public_send(m, *args, &block)
  else
    obj.public_send(m, *args)
  end
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



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

def model
  @model
end

#relationObject

Returns the value of attribute relation.



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

def relation
  @relation
end

#xObject

Returns the value of attribute x.



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

def x
  @x
end

#yObject

Returns the value of attribute y.



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

def y
  @y
end

Instance Method Details

#relation?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/export_to/presenter.rb', line 11

def relation?
  relation.present?
end