Class: Lutaml::Model::Validation::Registry

Inherits:
Object
  • Object
show all
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

Constructor Details

#initializeRegistry

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

#allObject



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_classesObject



50
51
52
# File 'lib/lutaml/model/validation/registry.rb', line 50

def rule_classes
  @rules.dup
end

#sizeObject



54
55
56
# File 'lib/lutaml/model/validation/registry.rb', line 54

def size
  @rules.size
end