Module: Representable::DSLAdditions
- Defined in:
- lib/representable.rb
Overview
Internal module for DSL sugar that should not go into the core library.
Instance Method Summary collapse
-
#inline_representer(base_module, name, options, &block) ⇒ Object
DISCUSS: separate module?.
-
#nested(name, options = {}, &block) ⇒ Object
Allows you to nest a block of properties in a separate section while still mapping them to the outer object.
- #property(name, options = {}, &block) ⇒ Object
Instance Method Details
#inline_representer(base_module, name, options, &block) ⇒ Object
DISCUSS: separate module?
181 182 183 184 185 186 |
# File 'lib/representable.rb', line 181 def inline_representer(base_module, name, , &block) # DISCUSS: separate module? Module.new do include *base_module # Representable::JSON or similar. instance_exec &block end end |
#nested(name, options = {}, &block) ⇒ Object
Allows you to nest a block of properties in a separate section while still mapping them to the outer object.
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/representable.rb', line 156 def nested(name, ={}, &block) = .merge( :decorator => true, :getter => lambda { |*| self }, :setter => lambda { |*| }, :instance => lambda { |*| self } ) property(name, , &block) end |
#property(name, options = {}, &block) ⇒ Object
167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/representable.rb', line 167 def property(name, ={}, &block) parent = representable_attrs[name] if block_given? [:extend] = inline_representer_for(parent, name, , &block) # FIXME: passing parent sucks since we don't use it all the time. end if [:inherit] parent..merge!() and return parent end # FIXME: can we handle this in super/Definition.new ? super end |