Class: Fluent::RemoveEmptyOutput::RubyPlaceholderExpander
- Inherits:
-
Object
- Object
- Fluent::RemoveEmptyOutput::RubyPlaceholderExpander
- Defined in:
- lib/fluent/plugin/out_remove_empty.rb
Defined Under Namespace
Classes: UndefOpenStruct
Instance Attribute Summary collapse
-
#log ⇒ Object
readonly
Returns the value of attribute log.
-
#placeholders ⇒ Object
readonly
Returns the value of attribute placeholders.
Instance Method Summary collapse
-
#expand(str) ⇒ Object
Replace placeholders in a string.
-
#initialize(log) ⇒ RubyPlaceholderExpander
constructor
A new instance of RubyPlaceholderExpander.
-
#prepare_placeholders(time, record, opts) ⇒ Object
Get placeholders as a struct.
Constructor Details
#initialize(log) ⇒ RubyPlaceholderExpander
Returns a new instance of RubyPlaceholderExpander.
145 146 147 |
# File 'lib/fluent/plugin/out_remove_empty.rb', line 145 def initialize(log) @log = log end |
Instance Attribute Details
#log ⇒ Object (readonly)
Returns the value of attribute log.
143 144 145 |
# File 'lib/fluent/plugin/out_remove_empty.rb', line 143 def log @log end |
#placeholders ⇒ Object (readonly)
Returns the value of attribute placeholders.
143 144 145 |
# File 'lib/fluent/plugin/out_remove_empty.rb', line 143 def placeholders @placeholders end |
Instance Method Details
#expand(str) ⇒ Object
Replace placeholders in a string
164 165 166 167 |
# File 'lib/fluent/plugin/out_remove_empty.rb', line 164 def (str) str = str.gsub(/\$\{([^}]+)\}/, '#{\1}') # ${..} => #{..} eval "\"#{str}\"", @placeholders.instance_eval { binding } end |
#prepare_placeholders(time, record, opts) ⇒ Object
Get placeholders as a struct
154 155 156 157 158 159 |
# File 'lib/fluent/plugin/out_remove_empty.rb', line 154 def prepare_placeholders(time, record, opts) struct = UndefOpenStruct.new(record) struct.time = Time.at(time) opts.each {|key, value| struct.__send__("#{key}=", value) } @placeholders = struct end |