module Representable::Declarative
Constants
- NestedBuilder
Public Instance Methods
collection(name, options={}, &block)
click to toggle source
# File lib/representable/declarative.rb, line 9 def collection(name, options={}, &block) property(name, options.merge(collection: true), &block) end
default_nested_class()
click to toggle source
# File lib/representable/declarative.rb, line 42 def default_nested_class Module.new # FIXME: make that unnecessary in Declarative end
definitions()
click to toggle source
# File lib/representable/declarative.rb, line 61 def definitions @definitions ||= Config.new(Representable::Definition) end
Also aliased as: representable_attrs
hash(name=nil, options={}, &block)
click to toggle source
Calls superclass method
# File lib/representable/declarative.rb, line 13 def hash(name=nil, options={}, &block) return super() unless name # allow Object.hash. options[:hash] = true property(name, options, &block) end
nested(name, options={}, &block)
click to toggle source
Allows you to nest a block of properties in a separate section while still mapping them to the original object.
# File lib/representable/declarative.rb, line 22 def nested(name, options={}, &block) options = options.merge( getter: ->(opts) { self }, setter: ->(opts) { }, instance: ->(opts) { self }, ) if block options[:_nested_builder] = Decorator.nested_builder options[:_base] = Decorator.default_nested_class end property(name, options, &block) end
nested_builder()
click to toggle source
# File lib/representable/declarative.rb, line 57 def nested_builder NestedBuilder end
representation_wrap=(name)
click to toggle source
# File lib/representable/declarative.rb, line 3 def representation_wrap=(name) heritage.record(:representation_wrap=, name) definitions.wrap = name end