Module: Representable::Declarative
- Includes:
- Declarative::Heritage::DSL, Declarative::Schema::DSL, Declarative::Schema::Feature
- Defined in:
- lib/representable/declarative.rb
Constant Summary collapse
- NestedBuilder =
->() do Module.new do include Representable # FIXME: do we really need this? feature(*[:_features]) include(*[:_base]) # base when :inherit, or in decorator. module_eval(&[:_block]) end end
Instance Method Summary collapse
- #collection(name, options = {}, &block) ⇒ Object
- #default_nested_class ⇒ Object
- #definitions ⇒ Object (also: #representable_attrs)
- #hash(name = nil, options = {}, &block) ⇒ Object
-
#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.
- #nested_builder ⇒ Object
- #representation_wrap=(name) ⇒ Object
Instance Method Details
#collection(name, options = {}, &block) ⇒ Object
14 15 16 |
# File 'lib/representable/declarative.rb', line 14 def collection(name, ={}, &block) property(name, .merge(collection: true), &block) end |
#default_nested_class ⇒ Object
47 48 49 |
# File 'lib/representable/declarative.rb', line 47 def default_nested_class Module.new # FIXME: make that unnecessary in Declarative end |
#definitions ⇒ Object Also known as: representable_attrs
66 67 68 |
# File 'lib/representable/declarative.rb', line 66 def definitions @definitions ||= Config.new(Representable::Definition) end |
#hash(name = nil, options = {}, &block) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/representable/declarative.rb', line 18 def hash(name=nil, ={}, &block) return super() unless name # allow Object.hash. [:hash] = true property(name, , &block) end |
#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.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/representable/declarative.rb', line 27 def nested(name, ={}, &block) = .merge( getter: ->(_opts) { self }, setter: ->(opts) { }, instance: ->(_opts) { self }, ) if block [:_nested_builder] = Decorator.nested_builder [:_base] = Decorator.default_nested_class end property(name, , &block) end |
#nested_builder ⇒ Object
62 63 64 |
# File 'lib/representable/declarative.rb', line 62 def nested_builder NestedBuilder end |
#representation_wrap=(name) ⇒ Object
8 9 10 11 12 |
# File 'lib/representable/declarative.rb', line 8 def representation_wrap=(name) heritage.record(:representation_wrap=, name) definitions.wrap = name end |