Module: Babl::Operators::Object::DSL
- Included in:
- Template
- Defined in:
- lib/babl/operators/object.rb
Instance Method Summary collapse
-
#object(*attrs, **nested) ⇒ Object
Create a JSON object node with static structure.
Instance Method Details
#object(*attrs, **nested) ⇒ Object
Create a JSON object node with static structure
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/babl/operators/object.rb', line 10 def object(*attrs, **nested) (attrs.map(&:to_sym) + nested.keys).group_by(&:itself).each_value do |keys| raise Errors::InvalidTemplate, "Duplicate key in object(): #{keys.first}" if keys.size > 1 end construct_terminal { |ctx| nodes = attrs .map { |name| [name.to_sym, unscoped.enter] }.to_h .merge(nested) .map { |k, v| [k, unscoped.call(v).builder.precompile( Nodes::TerminalValue.instance, ctx.merge(key: k, continue: nil) )] } .to_h Nodes::Object.new(nodes) } end |