mirror of
https://github.com/meineerde/rackstash.git
synced 2025-10-17 14:01:01 +00:00
Allow to specify a custom scope in Rackstash::Fields::Array#concat
This commit is contained in:
parent
8232d139f4
commit
c401a29ab3
@ -67,9 +67,11 @@ module Rackstash
|
|||||||
#
|
#
|
||||||
# @param array [Array, ::Array] an array of values. Each value is
|
# @param array [Array, ::Array] an array of values. Each value is
|
||||||
# normalized before being added to `self`.
|
# normalized before being added to `self`.
|
||||||
|
# @param scope [Object] if `array` or any of its (deeply-nested) values is
|
||||||
|
# a proc, it will be called in the instance scope of this object.
|
||||||
# @return [self]
|
# @return [self]
|
||||||
def concat(array)
|
def concat(array, scope: nil)
|
||||||
array = Array(normalize(array, wrap: false))
|
array = Array(normalize(array, wrap: false, scope: scope))
|
||||||
@raw.concat(array)
|
@raw.concat(array)
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|||||||
@ -143,6 +143,12 @@ describe Rackstash::Fields::Array do
|
|||||||
it 'resolves nested procs' do
|
it 'resolves nested procs' do
|
||||||
expect(array.concat(-> { [-> { :foo } ] } )).to contain_exactly 'foo'
|
expect(array.concat(-> { [-> { :foo } ] } )).to contain_exactly 'foo'
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'resolves nested procs with a custom scope' do
|
||||||
|
expect(
|
||||||
|
array.concat(-> { [self, -> { self.to_s.upcase } ] }, scope: :stuff )
|
||||||
|
).to contain_exactly 'stuff', 'STUFF'
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#empty?' do
|
describe '#empty?' do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user