Class: Webmate::BasePresenter

Inherits:
Object
  • Object
show all
Includes:
Presenters::Scoped
Defined in:
lib/webmate/presenters/base_presenter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Presenters::Scoped

#build_serialized

Constructor Details

#initialize(resources) ⇒ BasePresenter

Returns a new instance of BasePresenter.

Raises:

  • (ArgumentError)


7
8
9
10
11
# File 'lib/webmate/presenters/base_presenter.rb', line 7

def initialize(resources)
  raise ArgumentError, "Resources should not be blank" if resources.blank?
  @resources = resources
  @errors = []
end

Instance Attribute Details

#accessorObject

Returns the value of attribute accessor.



5
6
7
# File 'lib/webmate/presenters/base_presenter.rb', line 5

def accessor
  @accessor
end

#resourcesObject

Returns the value of attribute resources.



5
6
7
# File 'lib/webmate/presenters/base_presenter.rb', line 5

def resources
  @resources
end

Instance Method Details

#errorsObject



19
20
21
# File 'lib/webmate/presenters/base_presenter.rb', line 19

def errors
  @errors
end

#to_json(options = {}) ⇒ Object



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

def to_json(options = {})
  serialize_resource.to_json
end

#to_serializableObject



13
14
15
16
17
# File 'lib/webmate/presenters/base_presenter.rb', line 13

def to_serializable
  build_serialized default_resource do |object|
    attributes object.attributes.keys
  end
end