Class: Spec::DSL::CompositeProcBuilder

Inherits:
Array
  • Object
show all
Defined in:
lib/spec/dsl/composite_proc_builder.rb

Instance Method Summary collapse

Constructor Details

#initialize(callbacks = []) ⇒ CompositeProcBuilder

Returns a new instance of CompositeProcBuilder.



4
5
6
# File 'lib/spec/dsl/composite_proc_builder.rb', line 4

def initialize(callbacks=[])
  push(*callbacks)
end

Instance Method Details

#proc(&error_handler) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/spec/dsl/composite_proc_builder.rb', line 8

def proc(&error_handler)
  parts = self
  errors = []
  Proc.new do
    result = parts.collect do |part|
      begin
        if part.is_a?(UnboundMethod)
          part.bind(self).call
        else
          instance_eval(&part)
        end
      rescue Exception => e
        if error_handler
          error_handler.call(e)
        else
          errors << e
        end
      end
    end
    raise errors.first unless errors.empty?
    result
  end
end