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?
163 164 165 166 167 168 |
# File 'lib/representable.rb', line 163 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.
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/representable.rb', line 133 def nested(name, ={}, &block) = .merge( :use_decorator => true, :getter => lambda { |*| self }, :setter => lambda { |*| }, :instance => lambda { |*| self } ) # DISCUSS: should this be a macro just as :parse_strategy? property(name, , &block) end |
#property(name, options = {}, &block) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 |
# File 'lib/representable.rb', line 144 def property(name, ={}, &block) modules = [] if [:inherit] # TODO: move this to Definition. parent = representable_attrs[name] modules << parent[:extend].evaluate(nil) if parent[:extend]# we can savely assume this is _not_ a lambda. # DISCUSS: leave that in #representer_module? end # FIXME: can we handle this in super/Definition.new ? if block_given? handle_deprecated_inline_extend!(modules, ) [:extend] = inline_representer_for(modules, name, , &block) end return parent.merge!() if .delete(:inherit) super end |