Class: Fluent::YohoushiOutput::RubyPlaceholderExpander
- Inherits:
-
Object
- Object
- Fluent::YohoushiOutput::RubyPlaceholderExpander
- Defined in:
- lib/fluent/plugin/out_yohoushi.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.
205 206 207 |
# File 'lib/fluent/plugin/out_yohoushi.rb', line 205 def placeholders @placeholders end |
Instance Method Details
#expand(str) ⇒ Object
Replace placeholders in a string
222 223 224 225 |
# File 'lib/fluent/plugin/out_yohoushi.rb', line 222 def (str) str = str.gsub(/\$\{([^}]+)\}/, '#{\1}') # ${..} => #{..} eval "\"#{str}\"", @placeholders.instance_eval { binding } end |
#prepare_placeholders(time, record, opts) ⇒ Object
Get placeholders as a struct
212 213 214 215 216 217 |
# File 'lib/fluent/plugin/out_yohoushi.rb', line 212 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 |