Module: LogStash::StringInterpolation

Extended by:
StringInterpolation
Included in:
StringInterpolation
Defined in:
lib/logstash/string_interpolation.rb

Constant Summary collapse

MIN_FLOAT_BEFORE_SCI_NOT =

Floats outside of these upper and lower bounds are forcibly converted to scientific notation by Float#to_s

0.0001
MAX_FLOAT_BEFORE_SCI_NOT =
1000000000000000.0
CACHE =
ThreadSafe::Cache.new
TEMPLATE_TAG_REGEXP =
/%\{[^}]+\}/

Instance Method Summary collapse

Instance Method Details

#evaluate(event, template) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/logstash/string_interpolation.rb', line 17

def evaluate(event, template)
  if template.is_a?(Float) && (template < MIN_FLOAT_BEFORE_SCI_NOT || template >= MAX_FLOAT_BEFORE_SCI_NOT)
    return ("%.15f" % template).sub(/0*$/,"")
  end

  template = template.to_s

  return template if not_cachable?(template)

  compiled = CACHE.get_or_default(template, nil) || CACHE.put(template, compile_template(template))
  compiled.evaluate(event)
end