Class: Monolens::Core::Chain

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

Instance Attribute Summary

Attributes included from Lens

#options

Instance Method Summary collapse

Methods included from Lens

#fail!, included

Methods included from Lens::FetchSupport

#fetch_on

Constructor Details

#initialize(options, registry) ⇒ Chain

Returns a new instance of Chain.



8
9
10
11
# File 'lib/monolens/stdlib/core/chain.rb', line 8

def initialize(options, registry)
  super({}, registry)
  @lenses = options.map{|l| lens(l) }
end

Instance Method Details

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



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/monolens/stdlib/core/chain.rb', line 13

def call(arg, world = {})
  result = arg
  @lenses.each do |lens|
    done = false
    catch(:skip) do
      result = lens.call(result, world)
      done = true
    end
    break unless done
  end
  result
end