Class: Monolens::Object::Transform
- Inherits:
-
Object
- Object
- Monolens::Object::Transform
- Includes:
- Lens
- Defined in:
- lib/monolens/stdlib/object/transform.rb
Instance Attribute Summary
Attributes included from Lens
Instance Method Summary collapse
- #call(arg, world = {}) ⇒ Object
-
#initialize(options, registry) ⇒ Transform
constructor
A new instance of Transform.
Methods included from Lens
Methods included from Lens::FetchSupport
Constructor Details
#initialize(options, registry) ⇒ Transform
Returns a new instance of Transform.
11 12 13 14 15 16 17 |
# File 'lib/monolens/stdlib/object/transform.rb', line 11 def initialize(, registry) super(, registry) ts = option(:defn, {}) ts.each_pair do |k,v| ts[k] = lens(v) end end |
Instance Method Details
#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 |