Class: Ruby::Rego::Policy

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

Overview

Compiled policy for reuse across evaluations.

Instance Method Summary collapse

Constructor Details

#initialize(source, environment_pool: EnvironmentPool.new) ⇒ Policy

Create a compiled policy from source.

Parameters:

  • source (String)

    Rego source

  • environment_pool (EnvironmentPool) (defaults to: EnvironmentPool.new)

    optional pool override



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

def initialize(source, environment_pool: EnvironmentPool.new)
  @source = source.to_s
  @compiled_module = Ruby::Rego.compile(@source)
  @environment_pool = environment_pool
end

Instance Method Details

#evaluate(input: {}, data: {}, query: nil) ⇒ Result?

Evaluate the policy with the provided input and query.

Parameters:

  • input (Object) (defaults to: {})

    input document

  • data (Object) (defaults to: {})

    data document

  • query (Object, nil) (defaults to: nil)

    query path

Returns:

  • (Result, nil)

    evaluation result, or nil when a query is undefined



28
29
30
# File 'lib/ruby/rego/policy.rb', line 28

def evaluate(input: {}, data: {}, query: nil)
  ErrorHandling.wrap("evaluation") { evaluate_with_pool(input: input, data: data, query: query) }
end