mirror of
https://github.com/meineerde/rackstash.git
synced 2025-12-19 15:01:12 +00:00
Add FilterChain#to_a to get a plain Array representation of the chain
This commit is contained in:
parent
597f605e06
commit
6c145579ed
@ -259,6 +259,13 @@ module Rackstash
|
|||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Returns an Array representation of the filter chain.
|
||||||
|
#
|
||||||
|
# @return [Array<#call>] an array of filters
|
||||||
|
def to_a
|
||||||
|
synchronize { @filters.dup }
|
||||||
|
end
|
||||||
|
|
||||||
# @return [String] an Array-compatible string representation of `self`
|
# @return [String] an Array-compatible string representation of `self`
|
||||||
def to_s
|
def to_s
|
||||||
synchronize { @filters.to_s }
|
synchronize { @filters.to_s }
|
||||||
|
|||||||
@ -435,11 +435,28 @@ describe Rackstash::FilterChain do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#to_a' do
|
||||||
|
it 'returns the array representation' do
|
||||||
|
filter_chain << filter
|
||||||
|
|
||||||
|
expect(filter_chain.to_a)
|
||||||
|
.to be_instance_of(Array)
|
||||||
|
.and all be_equal(filter)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'returns a duplicate' do
|
||||||
|
filter_chain << a_filter
|
||||||
|
array = filter_chain.to_a
|
||||||
|
|
||||||
|
expect { array << a_filter }.not_to change { filter_chain.length }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
describe '#to_s' do
|
describe '#to_s' do
|
||||||
it 'returns the array representation' do
|
it 'returns the array representation' do
|
||||||
filter_chain << -> {}
|
filter_chain << -> {}
|
||||||
|
|
||||||
expect(filter_chain.to_s).to eql filter_chain.each.to_a.to_s
|
expect(filter_chain.to_s).to eql filter_chain.to_a.to_s
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user