Method: Monolens::Object::Transform#call

Defined in:
lib/monolens/stdlib/object/transform.rb

#call(arg, world = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/monolens/stdlib/object/transform.rb', line 19

def call(arg, world = {})
  is_hash!(arg, world)

  result = arg.dup
  option(:defn, {}).each_pair do |attr, sub_lens|
    deeper(world, attr) do |w|
      actual_attr, fetched = fetch_on(attr, arg)
      if actual_attr
        result[actual_attr] = sub_lens.call(fetched, w)
      else
        on_missing(result, attr, world)
      end
    end
  end
  result
end