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
- #expand(str, placeholders) ⇒ Object
-
#initialize(log) ⇒ PlaceholderExpander
constructor
A new instance of PlaceholderExpander.
- #prepare_placeholders(_record, tag, tag_parts, ec2_metadata) ⇒ Object
Constructor Details
#initialize(log) ⇒ PlaceholderExpander
Returns a new instance of PlaceholderExpander.
142 143 144 |
# File 'lib/fluent/plugin/ec2_metadata.rb', line 142 def initialize(log) @log = log end |
Instance Attribute Details
#placeholders ⇒ Object (readonly)
148 149 150 |
# File 'lib/fluent/plugin/ec2_metadata.rb', line 148 def placeholders @placeholders end |
Instance Method Details
#expand(str, placeholders) ⇒ Object
168 169 170 171 172 173 |
# File 'lib/fluent/plugin/ec2_metadata.rb', line 168 def (str, placeholders) 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
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
# File 'lib/fluent/plugin/ec2_metadata.rb', line 150 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 end |