Class: Ruby::Rego::WithModifiers::WithModifierContext

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby/rego/with_modifiers/with_modifier_context.rb

Overview

Applies a single with modifier in a given environment.

Instance Method Summary collapse

Constructor Details

#initialize(modifier:, environment:, expression_evaluator:) ⇒ WithModifierContext

Returns a new instance of WithModifierContext.

Parameters:



20
21
22
23
24
# File 'lib/ruby/rego/with_modifiers/with_modifier_context.rb', line 20

def initialize(modifier:, environment:, expression_evaluator:)
  @modifier = modifier
  @environment = environment
  @expression_evaluator = expression_evaluator
end

Instance Method Details

#apply {|environment| ... } ⇒ Object

Yield Parameters:

Returns:

  • (Object)

Raises:



28
29
30
31
32
33
# File 'lib/ruby/rego/with_modifiers/with_modifier_context.rb', line 28

def apply(&)
  return apply_reference(&) if target.is_a?(AST::Reference)
  return apply_variable(&) if target.is_a?(AST::Variable)

  raise EvaluationError.new("Unsupported with target: #{target.class}", rule: nil, location: target.location)
end