Module: Omnis::Transformer::ClassMethods
- Defined in:
- lib/omnis/transformer.rb
Instance Method Summary collapse
- #apply_to_value(value) ⇒ Object
- #extract(source, expr) ⇒ Object
- #extractor(obj) ⇒ Object
- #properties ⇒ Object
-
#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.
- #to_value(&block) ⇒ Object
Instance Method Details
#apply_to_value(value) ⇒ Object
54 55 56 |
# File 'lib/omnis/transformer.rb', line 54 def apply_to_value(value) @to_value ? @to_value.(value) : value end |
#extract(source, expr) ⇒ Object
62 63 64 |
# File 'lib/omnis/transformer.rb', line 62 def extract(source, expr) @extractor.extractor(expr).call(source) end |
#extractor(obj) ⇒ Object
58 59 60 |
# File 'lib/omnis/transformer.rb', line 58 def extractor(obj) @extractor = obj end |
#properties ⇒ Object
30 31 32 |
# File 'lib/omnis/transformer.rb', line 30 def properties @properties ||= {} end |
#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 |
#to_value(&block) ⇒ Object
50 51 52 |
# File 'lib/omnis/transformer.rb', line 50 def to_value(&block) @to_value = block end |