mirror of
https://github.com/meineerde/rackstash.git
synced 2025-12-19 15:01:12 +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
|
||||
# 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]
|
||||
def concat(array)
|
||||
array = Array(normalize(array, wrap: false))
|
||||
def concat(array, scope: nil)
|
||||
array = Array(normalize(array, wrap: false, scope: scope))
|
||||
@raw.concat(array)
|
||||
self
|
||||
end
|
||||
|
||||
@ -143,6 +143,12 @@ describe Rackstash::Fields::Array do
|
||||
it 'resolves nested procs' do
|
||||
expect(array.concat(-> { [-> { :foo } ] } )).to contain_exactly 'foo'
|
||||
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
|
||||
|
||||
describe '#empty?' do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user