Class: Fluent::Plugin::MultiConditionSelectorOutput::RubyPlaceholderExpander
- Inherits:
-
Object
- Object
- Fluent::Plugin::MultiConditionSelectorOutput::RubyPlaceholderExpander
- Defined in:
- lib/fluent/plugin/out_multi_condition_selector.rb
Overview
THIS CLASS MUST BE THREAD-SAFE
Defined Under Namespace
Classes: CleanroomExpander
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
Instance Method Summary collapse
-
#expand(str, placeholders, force_stringify = false) ⇒ Object
Expand string with placeholders.
-
#initialize(params) ⇒ RubyPlaceholderExpander
constructor
A new instance of RubyPlaceholderExpander.
-
#prepare_placeholders(placeholder_values) ⇒ Object
FIXME: 引数返すだけの関数があるので削除.
-
#preprocess_map(value, force_stringify = false) ⇒ Object
Preprocess record map to convert into ruby string expansion.
- #time_value(time) ⇒ Object
Constructor Details
#initialize(params) ⇒ RubyPlaceholderExpander
Returns a new instance of RubyPlaceholderExpander.
267 268 269 270 271 |
# File 'lib/fluent/plugin/out_multi_condition_selector.rb', line 267 def initialize(params) @log = params[:log] @auto_typecast = params[:auto_typecast] @cleanroom_expander = CleanroomExpander.new end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
265 266 267 |
# File 'lib/fluent/plugin/out_multi_condition_selector.rb', line 265 def log @log end |
Instance Method Details
#expand(str, placeholders, force_stringify = false) ⇒ Object
Expand string with placeholders
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/fluent/plugin/out_multi_condition_selector.rb', line 317 def (str, placeholders, force_stringify = false) # FIXME: tag情報は使用してなさそうなので, 不必要であれば @cleanroom_expander.( str, placeholders['tag'], placeholders['time'], placeholders['record'], placeholders['tag_parts'], placeholders['tag_prefix'], placeholders['tag_suffix'], placeholders['hostname'] ) rescue => e log.warn "record_reformer: failed to expand `#{str}`", :error_class => e.class, :error => e. log.warn_backtrace nil end |
#prepare_placeholders(placeholder_values) ⇒ Object
FIXME: 引数返すだけの関数があるので削除
310 311 312 |
# File 'lib/fluent/plugin/out_multi_condition_selector.rb', line 310 def prepare_placeholders(placeholder_values) placeholder_values end |
#preprocess_map(value, force_stringify = false) ⇒ Object
Preprocess record map to convert into ruby string expansion
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 |
# File 'lib/fluent/plugin/out_multi_condition_selector.rb', line 281 def preprocess_map(value, force_stringify = false) new_value = nil if value.is_a?(String) if @auto_typecast and !force_stringify num_placeholders = value.scan('${').size if num_placeholders == 1 and value.start_with?('${') && value.end_with?('}') new_value = value[2..-2] # ${..} => .. end end unless new_value new_value = "%Q[#{value.gsub('${', '#{')}]" # xx${..}xx => %Q[xx#{..}xx] end elsif value.is_a?(Hash) new_value = {} value.each_pair do |k, v| new_value[preprocess_map(k, true)] = preprocess_map(v) end elsif value.is_a?(Array) new_value = [] value.each_with_index do |v, i| new_value[i] = preprocess_map(v) end else new_value = value end new_value end |
#time_value(time) ⇒ Object
273 274 275 |
# File 'lib/fluent/plugin/out_multi_condition_selector.rb', line 273 def time_value(time) Time.at(time) end |