Method: Omnis::Transformer::ClassMethods#property
- Defined in:
- lib/omnis/transformer.rb
#property(name, expr = nil, opts = {}, &block) ⇒ Object
If an expr is provided it will be passed to the configured extractor, otherwise a block should be given. As last resort, it embeds a lambda to look for a class method with the name of the param (at runtime)
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/omnis/transformer.rb', line 37 def property(name, expr=nil, opts={}, &block) xtr = case when String === expr ; @extractor.extractor(expr) when block_given? ; block else ->(source) { self.send(name, source) } end Omnis::Transformer::Property.new(name, expr, opts, xtr).tap do |prop| properties[prop.name] = prop end end |