Class: Fluent::Plugin::RedisEnrichmentFilter::PlaceholderExpander
- Inherits:
-
Object
- Object
- Fluent::Plugin::RedisEnrichmentFilter::PlaceholderExpander
- Defined in:
- lib/fluent/plugin/filter_redis_enrichment.rb
Overview
The expand recurse loop from record_transformer filter plugin
Instance Method Summary collapse
- #expand(value, context = {}) ⇒ Object
-
#initialize(log) ⇒ PlaceholderExpander
constructor
A new instance of PlaceholderExpander.
Constructor Details
#initialize(log) ⇒ PlaceholderExpander
Returns a new instance of PlaceholderExpander.
254 255 256 257 |
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 254 def initialize(log) @log = log @cleanroom_expander = CleanroomExpander.new(log) end |
Instance Method Details
#expand(value, context = {}) ⇒ Object
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# File 'lib/fluent/plugin/filter_redis_enrichment.rb', line 259 def (value, context = {}) new_value = nil case value when String num_placeholders = value.scan('${').size if num_placeholders == 1 && value.start_with?('${') && value.end_with?('}') new_value = value[2..-2] # ${..} => .. end new_value ||= "%Q[#{value.gsub('${', '#{')}]" new_value = @cleanroom_expander.(new_value, **context) when Hash new_value = {} value.each_pair do |k, v| new_value[(k, context)] = (v, context) end when Array new_value = [] value.each_with_index do |v, i| new_value[i] = (v, context) end else new_value = value end new_value end |