Class: OpenTracing::Instrumentation::Bunny::RegexpRoutingKeySanitazer
- Inherits:
-
Object
- Object
- OpenTracing::Instrumentation::Bunny::RegexpRoutingKeySanitazer
- Defined in:
- lib/opentracing/instrumentation/bunny/regexp_routing_key_sanitazer.rb
Overview
Replace id into routing key with placeholder
Example:
sanitazer = RegexpRoutingKeySanitazer.new
sanitazer.sanitaze_routing_key('prefix.1234567890abcdef12345678')
# 'prefix.:object_id'
sanitazer.sanitaze_routing_key('prefix.123.suffix')
# 'prefix.:sequence_id.suffis'
Constant Summary collapse
- ROUTING_KEY_SEPARATOR =
'.'
- DEFAULT_REPLCE_REGEXP_MAP =
{ ':sequence_id' => /^\d+$/, ':object_id' => /^[0-9a-f]{24}$/, }.freeze
Instance Method Summary collapse
-
#initialize(replace_regexp_map: DEFAULT_REPLCE_REGEXP_MAP) ⇒ RegexpRoutingKeySanitazer
constructor
A new instance of RegexpRoutingKeySanitazer.
-
#sanitaze_routing_key(routing_key) ⇒ String
Sanitazed routing key.
Constructor Details
#initialize(replace_regexp_map: DEFAULT_REPLCE_REGEXP_MAP) ⇒ RegexpRoutingKeySanitazer
Returns a new instance of RegexpRoutingKeySanitazer.
26 27 28 |
# File 'lib/opentracing/instrumentation/bunny/regexp_routing_key_sanitazer.rb', line 26 def initialize(replace_regexp_map: DEFAULT_REPLCE_REGEXP_MAP) @replace_regexp_map = replace_regexp_map end |
Instance Method Details
#sanitaze_routing_key(routing_key) ⇒ String
Returns sanitazed routing key.
32 33 34 35 36 37 |
# File 'lib/opentracing/instrumentation/bunny/regexp_routing_key_sanitazer.rb', line 32 def sanitaze_routing_key(routing_key) routing_key .split(ROUTING_KEY_SEPARATOR) .map { |part| filter_part(part) } .join(ROUTING_KEY_SEPARATOR) end |