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) ⇒ 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.
125 126 127 |
# File 'lib/fluent/plugin/ec2_metadata.rb', line 125 def initialize(log) @log = log end |
Instance Attribute Details
#placeholders ⇒ Object (readonly)
131 132 133 |
# File 'lib/fluent/plugin/ec2_metadata.rb', line 131 def placeholders @placeholders end |
Instance Method Details
#expand(str) ⇒ Object
151 152 153 154 155 156 |
# File 'lib/fluent/plugin/ec2_metadata.rb', line 151 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
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/fluent/plugin/ec2_metadata.rb', line 133 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 |