Sha256: 12f82e233e7a65a47748f41b451e8ae010593ad327b0650ff3eb8f1734158727
Contents?: true
Size: 557 Bytes
Versions: 10
Compression:
Stored size: 557 Bytes
Contents
require "map" class MVCLI::Decoding def initialize @enrichments = Map.new do |h,k| h[k] = [] end end 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 def method_missing(name, &block) fail "must supply a block to transform value named '#{name}'" unless block @enrichments[name] << block return self end end
Version data entries
10 entries across 10 versions & 1 rubygems