Class: MVCLI::Decoding
- Inherits:
-
Object
- Object
- MVCLI::Decoding
- Defined in:
- lib/mvcli/decoding.rb
Instance Method Summary collapse
- #call(name, value, target = Object) ⇒ Object
-
#initialize ⇒ Decoding
constructor
A new instance of Decoding.
- #method_missing(name, &block) ⇒ Object
Constructor Details
#initialize ⇒ Decoding
Returns a new instance of Decoding.
4 5 6 7 8 |
# File 'lib/mvcli/decoding.rb', line 4 def initialize @enrichments = Map.new do |h,k| h[k] = [] end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, &block) ⇒ Object
20 21 22 23 24 |
# File 'lib/mvcli/decoding.rb', line 20 def method_missing(name, &block) fail "must supply a block to transform value named '#{name}'" unless block @enrichments[name] << block return self end |
Instance Method Details
#call(name, value, target = Object) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/mvcli/decoding.rb', line 10 def call(name, value, target = Object) if target.is_a?(Array) [value].flatten.map {|element| call name, element, target.first} else @enrichments[name].reduce value do |value, enrichment| enrichment.call value end end end |