Module: Babl::Operators::Static::DSL

Included in:
Template
Defined in:
lib/babl/operators/static.rb

Instance Method Summary collapse

Instance Method Details

#static(val) ⇒ Object

Create a static JSON value



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/babl/operators/static.rb', line 10

def static(val)
    sanitized_val = Nodes::TerminalValue.instance.render_object(val)

    case sanitized_val
    when ::String, ::Numeric
        frozen_val = sanitized_val.dup.freeze
        construct_terminal { Nodes::Constant.new(frozen_val, Schema::Primitive.new(frozen_val)) }
    when ::NilClass
        construct_terminal { Nodes::Constant::NULL }
    when ::TrueClass
        construct_terminal { Nodes::Constant::TRUE }
    when ::FalseClass
        construct_terminal { Nodes::Constant::FALSE }
    else call(sanitized_val)
    end
rescue Errors::RenderingError => exception
    raise Errors::InvalidTemplate, exception.message
end