Class: Monolens::Object::Extend
- Inherits:
-
Object
- Object
- Monolens::Object::Extend
- Includes:
- Lens
- Defined in:
- lib/monolens/stdlib/object/extend.rb
Instance Attribute Summary
Attributes included from Lens
Instance Method Summary collapse
- #call(arg, world = {}) ⇒ Object
-
#initialize(options, registry) ⇒ Extend
constructor
A new instance of Extend.
Methods included from Lens
Methods included from Lens::FetchSupport
Constructor Details
#initialize(options, registry) ⇒ Extend
Returns a new instance of Extend.
11 12 13 14 15 16 17 |
# File 'lib/monolens/stdlib/object/extend.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 35 36 |
# File 'lib/monolens/stdlib/object/extend.rb', line 19 def call(arg, world = {}) is_hash!(arg, world) result = arg.dup is_symbol = arg.keys.any?{|k| k.is_a?(Symbol) } option(:defn, {}).each_pair do |attr, lens| deeper(world, attr) do |w| actual = is_symbol ? attr.to_sym : attr.to_s begin result[actual] = lens.call(arg, w) rescue Monolens::LensError => ex strategy = option(:on_error, :fail) handle_error(strategy, ex, result, actual, world) end end end result end |