diff --git a/lib/rackstash/fields/array.rb b/lib/rackstash/fields/array.rb index 53af33d..3d27401 100644 --- a/lib/rackstash/fields/array.rb +++ b/lib/rackstash/fields/array.rb @@ -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 diff --git a/spec/rackstash/fields/array_spec.rb b/spec/rackstash/fields/array_spec.rb index 4a705a3..d193bea 100644 --- a/spec/rackstash/fields/array_spec.rb +++ b/spec/rackstash/fields/array_spec.rb @@ -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