Class: Ruby::Rego::Parser::RuleHeadPathBuilder
- Inherits:
-
Object
- Object
- Ruby::Rego::Parser::RuleHeadPathBuilder
- Defined in:
- lib/ruby/rego/parser/rule_head_builders.rb
Overview
Builds nested object values for rule head segments.
Instance Method Summary collapse
-
#call ⇒ Hash
-
#initialize(head:, segments:, location:) ⇒ RuleHeadPathBuilder
constructor
A new instance of RuleHeadPathBuilder.
Constructor Details
#initialize(head:, segments:, location:) ⇒ RuleHeadPathBuilder
Returns a new instance of RuleHeadPathBuilder.
12 13 14 15 16 |
# File 'lib/ruby/rego/parser/rule_head_builders.rb', line 12 def initialize(head:, segments:, location:) @head = head @segments = segments @location = location end |
Instance Method Details
#call ⇒ Hash
19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/ruby/rego/parser/rule_head_builders.rb', line 19 def call key_segment, *remaining = segments return head unless key_segment value_node = head[:value] || AST::BooleanLiteral.new(value: true, location: location) value_node = build_nested_value(remaining, value_node) head.merge( type: :partial_object, key: normalize(key_segment), value: value_node, nested: remaining.any? ) end |