Class: GenericViewMapper::Section

Inherits:
Object
  • Object
show all
Includes:
Import::DSL, GenericViewMapper::SchemaDefinition::DSL
Defined in:
lib/generic_view_mapper/view/section.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Import::DSL

#from_json, #from_yaml, #import, #json, #yaml

Methods included from GenericViewMapper::SchemaDefinition::DSL

#attribute, #attributes, #attributes=, #section

Constructor Details

#initialize(name) ⇒ Section

Returns a new instance of Section.



8
9
10
# File 'lib/generic_view_mapper/view/section.rb', line 8

def initialize(name)
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/generic_view_mapper/view/section.rb', line 6

def name
  @name
end

Instance Method Details

#field_nameObject



12
13
14
15
16
17
# File 'lib/generic_view_mapper/view/section.rb', line 12

def field_name
  name
    .to_s
    .camelize(:lower)
    .to_sym
end

#render(target, view_context) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/generic_view_mapper/view/section.rb', line 19

def render(target, view_context)
  {
    field_name => attributes.inject({}) do |accum, el|
      accum.merge(el.render(target, view_context))
    end
  }
end