Class: SimplePipeline::Pipe

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_pipeline/pipe.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{}

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Pipe

Returns a new instance of Pipe.



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

def initialize (options = {})
  @options = DEFAULT_OPTIONS.merge(options)
  @sections = []
end

Instance Method Details

#add(section) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'lib/simple_pipeline/pipe.rb', line 12

def add (section)
  begin
    raise ArgumentError, "invalid section - incorrect number of arguments for process() method (should be 1)" unless section.class.instance_method(:process).arity == 1
  rescue NameError
    raise ArgumentError, "invalid section - process() method not found"
  end

  @sections << section
end

#process(payload) ⇒ Object



26
27
28
29
30
# File 'lib/simple_pipeline/pipe.rb', line 26

def process (payload)
  @sections.each do |section|
    section.process(payload)
  end
end

#sizeObject Also known as: length



22
23
24
# File 'lib/simple_pipeline/pipe.rb', line 22

def size
  return @sections.size
end