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, data_path: nil) {|environment| ... } ⇒ Object

Parameters:

  • overridden (Object)
  • data_path (Array<String>, nil) (defaults to: nil)

    the data key-path this override names, tracked so a rule at that path is shadowed by the override.

Yield Parameters:

Returns:

  • (Object)


32
33
34
35
36
37
38
39
# File 'lib/ruby/rego/with_modifiers/with_modifier_root_scope.rb', line 32

def with_override(overridden, data_path: nil, &)
  if input_scope?
    environment.with_overrides(input: overridden, &)
  else
    paths = [data_path].compact
    environment.with_overrides(data: overridden, data_paths: paths, &)
  end
end