Class: Enumex::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/enumex/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#enumeratorObject (readonly)

Returns the value of attribute enumerator.



3
4
5
# File 'lib/enumex/base.rb', line 3

def enumerator
  @enumerator
end

#extendersObject (readonly)

Returns the value of attribute extenders.



3
4
5
# File 'lib/enumex/base.rb', line 3

def extenders
  @extenders
end

Instance Method Details

#attach_to(enumerator, &block) ⇒ Object



5
6
7
8
9
10
# File 'lib/enumex/base.rb', line 5

def attach_to(enumerator, &block)
  @enumerator = enumerator
  @block = block

  actions.empty? ? self : run
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/enumex/base.rb', line 16

def run
  actions.reset

  enumerator.each do |*args|
    actions.pre.extenders.any? {|ext| ext.execute(*args) }

    block.call(*args).tap do |result|
      actions.post.extenders.each {|ext| ext.execute(*args) }
    end
  end
end