mirror of
https://github.com/meineerde/rackstash.git
synced 2025-10-17 14:01:01 +00:00
Use a Concurrent::Hash instead of a Set for Fields::Tags
This makes the Rackstash::Fields::Tags class thread safe while still mantaining its existing semantincs, given that Ruby's set is also build on top of a simple Hash.
This commit is contained in:
parent
db8a5e50b5
commit
f4e85f7013
@ -11,18 +11,18 @@ module Rackstash
|
|||||||
module Fields
|
module Fields
|
||||||
class Tags < AbstractCollection
|
class Tags < AbstractCollection
|
||||||
def initialize
|
def initialize
|
||||||
@raw = Set.new
|
@raw = Concurrent::Hash.new
|
||||||
end
|
end
|
||||||
|
|
||||||
def <<(tag)
|
def <<(tag)
|
||||||
tag = resolve_value(tag)
|
tag = resolve_value(tag)
|
||||||
tag = utf8_encode(tag).freeze
|
tag = utf8_encode(tag).freeze
|
||||||
@raw << tag unless tag.empty?
|
@raw[tag] = true unless tag.empty?
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def as_json(*)
|
def as_json(*)
|
||||||
@raw.to_a
|
@raw.keys
|
||||||
end
|
end
|
||||||
alias to_ary as_json
|
alias to_ary as_json
|
||||||
alias to_a as_json
|
alias to_a as_json
|
||||||
@ -42,18 +42,18 @@ module Rackstash
|
|||||||
|
|
||||||
def merge!(tags, scope: nil)
|
def merge!(tags, scope: nil)
|
||||||
tags = normalize_tags(tags, scope: scope)
|
tags = normalize_tags(tags, scope: scope)
|
||||||
tags.reject!(&:empty?)
|
Array(tags).each do |tag|
|
||||||
|
@raw[tag] = true unless tag.empty?
|
||||||
@raw.merge tags
|
end
|
||||||
self
|
self
|
||||||
end
|
end
|
||||||
|
|
||||||
def tagged?(tag)
|
def tagged?(tag)
|
||||||
@raw.include? utf8_encode(tag)
|
@raw.key? utf8_encode(tag)
|
||||||
end
|
end
|
||||||
|
|
||||||
def to_set
|
def to_set
|
||||||
@raw.dup
|
Set.new to_a
|
||||||
end
|
end
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user