Class: Ruby::Rego::WithModifiers::WithModifierRootScope

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

Overview

Encapsulates input/data root access for with modifiers.

Constant Summary collapse

ROOT_NAMES =
%w[input data].freeze

Instance Method Summary collapse

Constructor Details

#initialize(environment:, name:, location: nil) ⇒ WithModifierRootScope

Returns a new instance of WithModifierRootScope.

Parameters:



15
16
17
18
19
20
# File 'lib/ruby/rego/with_modifiers/with_modifier_root_scope.rb', line 15

def initialize(environment:, name:, location: nil)
  @environment = environment
  @name = name
  @location = location
  validate_name
end

Instance Method Details

#base_valueObject

Returns:

  • (Object)


23
24
25
# File 'lib/ruby/rego/with_modifiers/with_modifier_root_scope.rb', line 23

def base_value
  input_scope? ? environment.input.to_ruby : environment.data.to_ruby
end

#with_override(overridden) {|environment| ... } ⇒ Object

Parameters:

  • overridden (Object)

Yield Parameters:

Returns:

  • (Object)


30
31
32
33
34
35
36
# File 'lib/ruby/rego/with_modifiers/with_modifier_root_scope.rb', line 30

def with_override(overridden, &)
  if input_scope?
    environment.with_overrides(input: overridden, &)
  else
    environment.with_overrides(data: overridden, &)
  end
end