Class: Intermodal::Mapping::Presenter

Inherits:
Mapper
  • Object
show all
Defined in:
lib/intermodal/mapping/presenter.rb

Constant Summary

Constants inherited from Mapper

Mapper::EXCLUDE_NILS, Mapper::INCLUDE_NILS

Class Method Summary collapse

Methods inherited from Mapper

exclude_properties, map_attribute, map_attributes, maps, presenters, property_mapping

Methods included from DSL::PresentationHelpers

#attribute, #helper, #map_to, #maybe, #params, #presenter, #to_datetime, #to_presentation

Class Method Details

.call(resource, options = {}) ⇒ Object



23
24
25
26
27
28
29
30
31
# File 'lib/intermodal/mapping/presenter.rb', line 23

def call(resource, options = {})
  _scope = options[:scope] || :default

  if options[:root] || options[:always_nest_collections]
    { (options[:root].is_a?(TrueClass) || options[:root].nil? ? model_name(resource) : options[:root]) => map_attributes(resource, _scope) }
  else
    map_attributes(resource, _scope)
  end
end

.model_name(resource) ⇒ Object



19
20
21
# File 'lib/intermodal/mapping/presenter.rb', line 19

def model_name(resource)
  resource.class.name.demodulize.underscore
end