Class: Fluent::RecordReformerOutput::RubyPlaceholderExpander
- Inherits:
-
Object
- Object
- Fluent::RecordReformerOutput::RubyPlaceholderExpander
- Defined in:
- lib/fluent/plugin/out_record_reformer.rb
Defined Under Namespace
Classes: UndefOpenStruct
Instance Attribute Summary collapse
-
#placeholders ⇒ Object
readonly
Returns the value of attribute placeholders.
Instance Method Summary collapse
-
#expand(str) ⇒ Object
Replace placeholders in a string.
-
#prepare_placeholders(time, record, opts) ⇒ Object
Get placeholders as a struct.
Instance Attribute Details
#placeholders ⇒ Object (readonly)
Returns the value of attribute placeholders.
137 138 139 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 137 def placeholders @placeholders end |
Instance Method Details
#expand(str) ⇒ Object
Replace placeholders in a string
154 155 156 157 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 154 def (str) str = str.gsub(/\$\{([^}]+)\}/, '#{\1}') # ${..} => #{..} eval "\"#{str}\"", @placeholders.instance_eval { binding } end |
#prepare_placeholders(time, record, opts) ⇒ Object
Get placeholders as a struct
144 145 146 147 148 149 |
# File 'lib/fluent/plugin/out_record_reformer.rb', line 144 def prepare_placeholders(time, record, opts) struct = UndefOpenStruct.new(record) struct.time = Time.at(time) opts.each {|key, val| struct.__send__("#{key}=", val) } @placeholders = struct end |