Class: Monolens::Object::Select

Inherits:
Object
  • Object
show all
Includes:
Lens
Defined in:
lib/monolens/stdlib/object/select.rb

Instance Attribute Summary

Attributes included from Lens

#options

Instance Method Summary collapse

Methods included from Lens

#fail!, included, #initialize

Methods included from Lens::FetchSupport

#fetch_on

Instance Method Details

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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/monolens/stdlib/object/select.rb', line 16

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

  result = {}
  is_symbol = arg.keys.any?{|k| k.is_a?(Symbol) }
  defn.each_pair do |new_attr, selector|
    new_attr = is_symbol ? new_attr.to_sym : new_attr.to_s

    deeper(world, new_attr) do |w|
      catch (:skip) do
        value = do_select(arg, selector, w)
        result[new_attr] = value
      end
    end
  end
  result
end