Module: Smith::Doctor::Checks::PersistenceRegistry
- Defined in:
- lib/smith/doctor/checks/persistence_registry.rb
Class Method Summary collapse
- .ar_backed?(klass) ⇒ Boolean
- .check(report, mode) ⇒ Object
- .check_database_registry(report) ⇒ Object
- .resolve_registry_class ⇒ Object
- .verify_registry_table_and_records(report, registry_class) ⇒ Object
Class Method Details
.ar_backed?(klass) ⇒ Boolean
52 53 54 55 56 |
# File 'lib/smith/doctor/checks/persistence_registry.rb', line 52 def self.ar_backed?(klass) klass.ancestors.any? { |a| a.name&.include?("ActiveRecord::Base") } rescue StandardError false end |
.check(report, mode) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/smith/doctor/checks/persistence_registry.rb', line 7 def self.check(report, mode) case mode when :database check_database_registry(report) when :bundled report.add(name: "persistence.model_registry_mode", status: :pass, message: "Model registry mode: bundled (explicit)") else report.add( name: "persistence.model_registry_mode", status: :pass, message: "Model registry mode: bundled fallback (default)", detail: "Set config.ruby_llm_model_registry = :database if DB-backed registry is required" ) end end |
.check_database_registry(report) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/smith/doctor/checks/persistence_registry.rb', line 23 def self.check_database_registry(report) registry_class = resolve_registry_class unless registry_class report.add(name: "persistence.model_registry_mode", status: :fail, message: "DB-backed model registry required but registry class not resolvable", detail: "RubyLLM.config.model_registry_class could not be resolved to a constant") return end unless ar_backed?(registry_class) report.add(name: "persistence.model_registry_mode", status: :fail, message: "DB-backed model registry required but class is not ActiveRecord-backed", detail: "#{registry_class.name} does not inherit from ActiveRecord::Base") return end verify_registry_table_and_records(report, registry_class) end |
.resolve_registry_class ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/smith/doctor/checks/persistence_registry.rb', line 42 def self.resolve_registry_class raw = ::RubyLLM.config.model_registry_class return nil unless raw klass = raw.is_a?(String) ? Object.const_get(raw) : raw klass.is_a?(Class) ? klass : nil rescue NameError nil end |
.verify_registry_table_and_records(report, registry_class) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/smith/doctor/checks/persistence_registry.rb', line 58 def self.verify_registry_table_and_records(report, registry_class) unless registry_class.table_exists? report.add(name: "persistence.model_registry_mode", status: :fail, message: "DB-backed model registry table missing", detail: "#{registry_class.table_name} does not exist") return end count = registry_class.count if count.positive? report.add(name: "persistence.model_registry_mode", status: :pass, message: "DB-backed model registry operational (#{count} records)") else report.add(name: "persistence.model_registry_mode", status: :fail, message: "DB-backed model registry table exists but is empty", detail: "Run ruby_llm model sync or seeding task") end rescue StandardError => e report.add(name: "persistence.model_registry_mode", status: :fail, message: "DB-backed model registry query failed", detail: e.) end |