Class: BasePresenter

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

Defined Under Namespace

Classes: NilPresenter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(presentable, curr_user = nil) ⇒ BasePresenter

Returns a new instance of BasePresenter.


18
19
20
21
# File 'app/presenters/base_presenter.rb', line 18

def initialize(presentable, curr_user=nil)
  @presentable = presentable
  @current_user = curr_user
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object


23
24
25
# File 'app/presenters/base_presenter.rb', line 23

def method_missing(method, *args)
  @presentable.public_send(method, *args)
end

Instance Attribute Details

#current_userObject (readonly)

Returns the value of attribute current_user


4
5
6
# File 'app/presenters/base_presenter.rb', line 4

def current_user
  @current_user
end

Class Method Details

.as_collection(collection, method = :as_json, *args) ⇒ Object


13
14
15
# File 'app/presenters/base_presenter.rb', line 13

def as_collection(collection, method=:as_json, *args)
  collection.map{|object| self.new(object, *args).send(method) }
end

.new(*args) ⇒ Object


8
9
10
11
# File 'app/presenters/base_presenter.rb', line 8

def new(*args)
  return NilPresenter.new if args[0].nil?
  super *args
end