Method: Representable::Declarative#nested

Defined in:
lib/representable/declarative.rb

#nested(name, options = {}, &block) ⇒ Object

Allows you to nest a block of properties in a separate section while still mapping them to the original object.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/representable/declarative.rb', line 22

def nested(name, options={}, &block)
  options = options.merge(
    getter:   ->(options) { self },
    setter:   ->(options) { },
    instance: ->(options) { self },
  )

  if block
    options[:_nested_builder] = Decorator.nested_builder
    options[:_base]           = Decorator.default_nested_class
  end

  property(name, options, &block)
end