1
0
mirror of https://github.com/meineerde/rackstash.git synced 2025-12-19 15:01:12 +00:00

Return the flows object in Rackstash::Flows#each

This commit is contained in:
Holger Just 2017-07-15 16:26:14 +02:00
parent 1da5ae4a38
commit 364426f228
2 changed files with 6 additions and 5 deletions

View File

@ -61,17 +61,18 @@ module Rackstash
# a parameter. We only yield non-nil elements. Concurrent changes to `self`
# do not affect the running enumeration.
#
# An Enumerator is returned if no block is given.
# An `Enumerator` is returned if no block is given.
#
# @yield [flow] calls the given block once for each flow
# @yieldparam flow [Flow] the yielded flow
# @return [Enumerator, Array<Flow>] Returns an array of the flows if a
# block was given or an `Enumerator` if no block was given.
# @return [Enumerator, self] `self` if a block was given or an `Enumerator`
# if no block was given.
def each
return enum_for(__method__) unless block_given?
to_a.each do |flow|
yield flow
end
self
end
# @return [Boolean] `true` if `self` contains no elements, `false` otherwise

View File

@ -128,9 +128,9 @@ describe Rackstash::Flows do
expect { |b| flows.each(&b) }.to yield_control.once
end
it 'returns an array if a block was provided' do
it 'returns the flow if a block was provided' do
flows << a_flow
expect(flows.each {}).to be_instance_of Array
expect(flows.each {}).to equal flows
end
it 'returns an Enumerator if no block was provided' do