Class: Lutaml::Model::Validation::Registry
- Inherits:
-
Object
- Object
- Lutaml::Model::Validation::Registry
- Defined in:
- lib/lutaml/model/validation/registry.rb
Overview
Instance-based rule registry. Register rule classes, look up by code or category, and instantiate all registered rules for validation runs.
Instance Method Summary collapse
- #all ⇒ Object
- #auto_discover(dir, pattern: "**/*_rule.rb") ⇒ Object
- #find(code) ⇒ Object
- #for_category(category) ⇒ Object
-
#initialize ⇒ Registry
constructor
A new instance of Registry.
- #register(rule_class) ⇒ Object
- #reset! ⇒ Object
- #rule_classes ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ Registry
Returns a new instance of Registry.
10 11 12 13 14 |
# File 'lib/lutaml/model/validation/registry.rb', line 10 def initialize @rules = [] @mutex = Mutex.new @all = nil end |
Instance Method Details
#all ⇒ Object
29 30 31 32 33 |
# File 'lib/lutaml/model/validation/registry.rb', line 29 def all @mutex.synchronize do @all ||= @rules.map(&:new) end end |
#auto_discover(dir, pattern: "**/*_rule.rb") ⇒ Object
25 26 27 |
# File 'lib/lutaml/model/validation/registry.rb', line 25 def auto_discover(dir, pattern: "**/*_rule.rb") Dir.glob(File.join(dir, pattern)).each { |path| require path } end |
#find(code) ⇒ Object
39 40 41 |
# File 'lib/lutaml/model/validation/registry.rb', line 39 def find(code) all.find { |r| r.code == code } end |
#for_category(category) ⇒ Object
35 36 37 |
# File 'lib/lutaml/model/validation/registry.rb', line 35 def for_category(category) all.select { |r| r.category == category } end |
#register(rule_class) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/lutaml/model/validation/registry.rb', line 16 def register(rule_class) @mutex.synchronize do return if @rules.include?(rule_class) @rules << rule_class @all = nil end end |
#reset! ⇒ Object
43 44 45 46 47 48 |
# File 'lib/lutaml/model/validation/registry.rb', line 43 def reset! @mutex.synchronize do @rules.clear @all = nil end end |
#rule_classes ⇒ Object
50 51 52 |
# File 'lib/lutaml/model/validation/registry.rb', line 50 def rule_classes @rules.dup end |
#size ⇒ Object
54 55 56 |
# File 'lib/lutaml/model/validation/registry.rb', line 54 def size @rules.size end |