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
9 10 11 |
# File 'lib/representable/declarative.rb', line 9 def collection(name, ={}, &block) property(name, .merge(collection: true), &block) end |
#default_nested_class ⇒ Object
42 43 44 |
# File 'lib/representable/declarative.rb', line 42 def default_nested_class Module.new # FIXME: make that unnecessary in Declarative end |
#definitions ⇒ Object Also known as: representable_attrs
61 62 63 |
# File 'lib/representable/declarative.rb', line 61 def definitions @definitions ||= Config.new(Representable::Definition) end |
#hash(name = nil, options = {}, &block) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/representable/declarative.rb', line 13 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.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/representable/declarative.rb', line 22 def nested(name, ={}, &block) = .merge( getter: ->() { self }, setter: ->() { }, instance: ->() { self }, ) if block [:_nested_builder] = Decorator.nested_builder [:_base] = Decorator.default_nested_class end property(name, , &block) end |
#nested_builder ⇒ Object
57 58 59 |
# File 'lib/representable/declarative.rb', line 57 def nested_builder NestedBuilder end |
#representation_wrap=(name) ⇒ Object
3 4 5 6 7 |
# File 'lib/representable/declarative.rb', line 3 def representation_wrap=(name) heritage.record(:representation_wrap=, name) definitions.wrap = name end |