Class: Ruby::Rego::Compiler
- Inherits:
-
Object
- Object
- Ruby::Rego::Compiler
- Defined in:
- lib/ruby/rego/compiler.rb
Overview
Compiles AST modules into indexed structures for evaluation.
Instance Method Summary collapse
-
#check_conflicts(rules) ⇒ void
Validate a rule set for conflicts.
-
#check_safety(rule) ⇒ void
Validate a rule for safety (unbound variables).
-
#compile(ast_module) ⇒ CompiledModule
Compile an AST module into a compiled module.
-
#compile_set(modules) ⇒ CompiledPolicySet
Compile a named set of module sources into a policy set.
-
#index_rules(rules) ⇒ Hash{String => Array<AST::Rule>}
Index rules by name.
-
#initialize(builtin_registry: Builtins::BuiltinRegistry.instance, default_rule_validator: nil) ⇒ Compiler
constructor
Create a compiler instance.
Constructor Details
#initialize(builtin_registry: Builtins::BuiltinRegistry.instance, default_rule_validator: nil) ⇒ Compiler
Create a compiler instance.
27 28 29 30 |
# File 'lib/ruby/rego/compiler.rb', line 27 def initialize(builtin_registry: Builtins::BuiltinRegistry.instance, default_rule_validator: nil) @builtin_registry = builtin_registry @default_rule_validator = default_rule_validator end |
Instance Method Details
#check_conflicts(rules) ⇒ void
This method returns an undefined value.
Validate a rule set for conflicts.
70 71 72 |
# File 'lib/ruby/rego/compiler.rb', line 70 def check_conflicts(rules) conflict_checker.check(rules) end |
#check_safety(rule) ⇒ void
This method returns an undefined value.
Validate a rule for safety (unbound variables).
78 79 80 |
# File 'lib/ruby/rego/compiler.rb', line 78 def check_safety(rule) safety_checker.check_rule(rule) end |
#compile(ast_module) ⇒ CompiledModule
Compile an AST module into a compiled module.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ruby/rego/compiler.rb', line 36 def compile(ast_module) rules_by_name = compile_rules(ast_module) package_path = ast_module.package.path dependency_graph = dependency_graph_builder.build(rules_by_name, package_path) artifacts = CompilationArtifacts.new( rules_by_name: rules_by_name, package_path: package_path, dependency_graph: dependency_graph ) CompiledModuleBuilder.build(ast_module, artifacts) end |
#compile_set(modules) ⇒ CompiledPolicySet
Compile a named set of module sources into a policy set.
52 53 54 55 56 |
# File 'lib/ruby/rego/compiler.rb', line 52 def compile_set(modules) ast_modules = parse_named_modules(modules) merged = merge_modules_by_package(ast_modules) CompiledPolicySet.new(merged.map { |ast_module| compile(ast_module) }) end |
#index_rules(rules) ⇒ Hash{String => Array<AST::Rule>}
Index rules by name.
62 63 64 |
# File 'lib/ruby/rego/compiler.rb', line 62 def index_rules(rules) rule_indexer.index(rules) end |