mirror of
https://github.com/meineerde/rackstash.git
synced 2026-01-31 17:27:13 +00:00
Allow to pass a scope with procs when merging Tags
This commit is contained in:
parent
0292a7eacb
commit
e9c98fc648
@ -41,7 +41,7 @@ module Rackstash
|
||||
end
|
||||
|
||||
def merge!(tags, scope: nil)
|
||||
@raw.merge normalize_tags(tags)
|
||||
@raw.merge normalize_tags(tags, scope: scope)
|
||||
self
|
||||
end
|
||||
|
||||
@ -61,11 +61,11 @@ module Rackstash
|
||||
if value.is_a?(self.class)
|
||||
value.to_a
|
||||
elsif value.is_a?(Set)
|
||||
value = value.map { |tag| normalize_tags(tag) }
|
||||
value = value.map { |tag| normalize_tags(tag, scope: scope) }
|
||||
value.flatten!
|
||||
value
|
||||
elsif value.respond_to?(:to_ary)
|
||||
value = value.to_ary.map { |tag| normalize_tags(tag) }
|
||||
value = value.to_ary.map { |tag| normalize_tags(tag, scope: scope) }
|
||||
value.flatten!
|
||||
value
|
||||
else
|
||||
|
||||
@ -11,7 +11,7 @@ describe Rackstash::Fields::Tags do
|
||||
let(:tags) { Rackstash::Fields::Tags.new }
|
||||
|
||||
describe '#<<' do
|
||||
it 'calls merge!' do
|
||||
it 'adds a single tag' do
|
||||
tags << 'tag'
|
||||
expect(tags.tagged?('tag')).to be true
|
||||
end
|
||||
@ -94,7 +94,10 @@ describe Rackstash::Fields::Tags do
|
||||
|
||||
it 'resolves procs' do
|
||||
tags.merge! [-> { 123 }]
|
||||
expect(tags.tagged?('123')).to be true
|
||||
expect(tags.to_a).to eql ['123']
|
||||
|
||||
tags.merge! [-> { self }], scope: :foo
|
||||
expect(tags.to_a).to eql ['123', 'foo']
|
||||
end
|
||||
|
||||
it 'flattens arguments' do
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user