Class: Ruby::Rego::CompiledModule
- Inherits:
-
Object
- Object
- Ruby::Rego::CompiledModule
- Defined in:
- lib/ruby/rego/compiled_module.rb
Overview
Bundles compiled rule metadata for fast evaluation.
Instance Attribute Summary collapse
-
#dependency_graph ⇒ Hash{String => Array<String>}
readonly
Dependency graph for rule evaluation ordering.
-
#imports ⇒ Array<AST::Import>
readonly
Import declarations.
-
#package_path ⇒ Array<String>
readonly
The module package path.
-
#rules_by_name ⇒ Hash{String => Array<AST::Rule>}
readonly
Rules indexed by name.
Instance Method Summary collapse
-
#has_rule?(name) ⇒ Boolean
Check whether a rule exists.
-
#initialize(package_path:, rules_by_name:, imports: [], dependency_graph: {}) ⇒ CompiledModule
constructor
Create a compiled module bundle.
-
#lookup_rule(name) ⇒ Array<AST::Rule>
Fetch rules for a given name.
-
#rule_names ⇒ Array<String>
List all rule names.
Constructor Details
#initialize(package_path:, rules_by_name:, imports: [], dependency_graph: {}) ⇒ CompiledModule
Create a compiled module bundle.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/ruby/rego/compiled_module.rb', line 13 def initialize(package_path:, rules_by_name:, imports: [], dependency_graph: {}) state = { package_path: package_path, rules_by_name: rules_by_name, imports: imports, dependency_graph: dependency_graph } @package_path, @rules_by_name, @imports, @dependency_graph = Normalizer.new(state).normalize end |
Instance Attribute Details
#dependency_graph ⇒ Hash{String => Array<String>} (readonly)
Dependency graph for rule evaluation ordering.
44 45 46 |
# File 'lib/ruby/rego/compiled_module.rb', line 44 def dependency_graph @dependency_graph end |
#imports ⇒ Array<AST::Import> (readonly)
Import declarations.
39 40 41 |
# File 'lib/ruby/rego/compiled_module.rb', line 39 def imports @imports end |
#package_path ⇒ Array<String> (readonly)
The module package path.
29 30 31 |
# File 'lib/ruby/rego/compiled_module.rb', line 29 def package_path @package_path end |
#rules_by_name ⇒ Hash{String => Array<AST::Rule>} (readonly)
Rules indexed by name.
34 35 36 |
# File 'lib/ruby/rego/compiled_module.rb', line 34 def rules_by_name @rules_by_name end |
Instance Method Details
#has_rule?(name) ⇒ Boolean
Check whether a rule exists.
rubocop:disable Naming/PredicatePrefix
66 67 68 |
# File 'lib/ruby/rego/compiled_module.rb', line 66 def has_rule?(name) rules_by_name.key?(name.to_s) end |
#lookup_rule(name) ⇒ Array<AST::Rule>
Fetch rules for a given name.
50 51 52 |
# File 'lib/ruby/rego/compiled_module.rb', line 50 def lookup_rule(name) rules_by_name.fetch(name.to_s) { empty_rules } end |
#rule_names ⇒ Array<String>
List all rule names.
57 58 59 |
# File 'lib/ruby/rego/compiled_module.rb', line 57 def rule_names rules_by_name.keys end |