Class: Fluent::EC2Metadata::PlaceholderExpander
- Inherits:
-
Object
- Object
- Fluent::EC2Metadata::PlaceholderExpander
- Defined in:
- lib/fluent/plugin/ec2_metadata.rb
Instance Attribute Summary collapse
- #placeholders ⇒ Object readonly
Instance Method Summary collapse
Instance Attribute Details
#placeholders ⇒ Object (readonly)
126 127 128 |
# File 'lib/fluent/plugin/ec2_metadata.rb', line 126 def placeholders @placeholders end |
Instance Method Details
#expand(str) ⇒ Object
146 147 148 149 150 151 |
# File 'lib/fluent/plugin/ec2_metadata.rb', line 146 def (str) str.gsub(/(\${[a-z_]+(\[-?[0-9]+\])?}|__[A-Z_]+__)/) { $log.warn "ec2-metadata: unknown placeholder `#{$1}` found in a tag `#{@placeholders['${tag}']}`" unless @placeholders.include?($1) @placeholders[$1] } end |
#prepare_placeholders(_record, tag, tag_parts, ec2_metadata) ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/fluent/plugin/ec2_metadata.rb', line 128 def prepare_placeholders(_record, tag, tag_parts, ) placeholders = { '${tag}' => tag, } size = tag_parts.size tag_parts.each_with_index { |t, idx| placeholders.store("${tag_parts[#{idx}]}", t) placeholders.store("${tag_parts[#{idx-size}]}", t) # support tag_parts[-1] } .each { |k, v| placeholders.store("${#{k}}", v) } @placeholders = placeholders end |