Class: SimplePipeline

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_pipeline.rb,
lib/simple_pipeline/timeout.rb,
lib/simple_pipeline/version.rb,
lib/simple_pipeline/validation.rb

Defined Under Namespace

Modules: Timeout, Validation

Constant Summary collapse

VERSION =
"0.0.6"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSimplePipeline

Returns a new instance of SimplePipeline.



10
11
12
13
14
# File 'lib/simple_pipeline.rb', line 10

def initialize
    @pipe_order = []
    @pipe_options = {}
    @errors = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



8
9
10
# File 'lib/simple_pipeline.rb', line 8

def errors
  @errors
end

Instance Method Details

#add(pipe, options = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/simple_pipeline.rb', line 16

def add (pipe, options = {})
    process_method = options[:process_method] || :process 

    begin
        raise ArgumentError, "invalid pipe - incorrect number of arguments for #{process_method}() method (should be 1)" unless pipe.class.instance_method(process_method).arity == 1
    rescue NameError
        raise ArgumentError, "invalid pipe - #{process_method}() method not found"
    end

    @pipe_order << pipe
    @pipe_options[pipe] = options

    return pipe
end

#process(payload) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/simple_pipeline.rb', line 35

def process (payload)
    @errors.clear

    @pipe_order.each do |pipe|
        begin
            validate_payload(pipe, payload)
            invoke_process_with_timeout(pipe, payload, get_timeout(pipe))
        rescue
            raise $! unless continue_on_error?($!, pipe)
            @errors << $!
        end
    end
end

#sizeObject Also known as: length



31
32
33
# File 'lib/simple_pipeline.rb', line 31

def size
    return @pipe_order.size
end