Class: Ruby::Rego::Evaluator::TemplateValueFormatter
- Inherits:
-
Object
- Object
- Ruby::Rego::Evaluator::TemplateValueFormatter
- Defined in:
- lib/ruby/rego/evaluator/template_value_formatter.rb
Overview
Formats template string values using a stable JSON representation.
Instance Method Summary collapse
-
#canonical_value ⇒ Object
-
#initialize(value) ⇒ TemplateValueFormatter
constructor
A new instance of TemplateValueFormatter.
-
#render ⇒ String
Constructor Details
#initialize(value) ⇒ TemplateValueFormatter
Returns a new instance of TemplateValueFormatter.
11 12 13 |
# File 'lib/ruby/rego/evaluator/template_value_formatter.rb', line 11 def initialize(value) @value = value end |
Instance Method Details
#canonical_value ⇒ Object
26 27 28 29 30 31 32 33 |
# File 'lib/ruby/rego/evaluator/template_value_formatter.rb', line 26 def canonical_value case value when Hash then canonicalize_hash when Array then canonicalize_array when Set then canonicalize_set else value end end |
#render ⇒ String
16 17 18 19 20 21 22 23 |
# File 'lib/ruby/rego/evaluator/template_value_formatter.rb', line 16 def render case value when NilClass then "null" when String then value when Array, Hash, Set then JSON.generate(canonical_value) else value.to_s end end |