Class: Rjq::AST::ObjectLiteral

Inherits:
Node
  • Object
show all
Defined in:
lib/rjq/ast.rb

Defined Under Namespace

Classes: Pair

Instance Attribute Summary collapse

Attributes inherited from Node

#source_span

Instance Method Summary collapse

Methods inherited from Node

#assign_value, #invalid_path_message, #paths, #take, #with_source_span

Constructor Details

#initialize(pairs) ⇒ ObjectLiteral

Returns a new instance of ObjectLiteral.



643
644
645
# File 'lib/rjq/ast.rb', line 643

def initialize(pairs)
  @pairs = pairs
end

Instance Attribute Details

#pairsObject (readonly)

Returns the value of attribute pairs.



641
642
643
# File 'lib/rjq/ast.rb', line 641

def pairs
  @pairs
end

Instance Method Details

#eval(input, context) ⇒ Object



647
648
649
650
651
652
653
654
655
656
657
658
659
# File 'lib/rjq/ast.rb', line 647

def eval(input, context)
  objects = [{}]
  @pairs.each do |pair|
    key_values = key_outputs(pair.key, input, context)
    value_values = pair.value.eval(input, context)
    objects = objects.flat_map do |object|
      key_values.flat_map do |key|
        value_values.map { |value| object.merge(key.to_s => value) }
      end
    end
  end
  objects
end