Module: AsktiveRecord::SchemaLoader
- Included in:
- Model::ClassMethods, AsktiveRecord::Service::ClassMethods
- Defined in:
- lib/asktive_record/schema_loader.rb
Overview
SchemaLoader provides shared schema loading functionality used by both Model::ClassMethods and Service::ClassMethods. It handles reading schema files, falling back to structure.sql, and providing clear error messages.
Instance Method Summary collapse
-
#ensure_schema_is_not_empty!(schema_content) ⇒ Object
Validates that the schema content is not empty.
-
#load_schema_content ⇒ String
Loads the database schema content from the configured path.
-
#validate_llm_api_key! ⇒ Object
Validates that the LLM API key is configured.
Instance Method Details
#ensure_schema_is_not_empty!(schema_content) ⇒ Object
Validates that the schema content is not empty.
28 29 30 31 32 33 |
# File 'lib/asktive_record/schema_loader.rb', line 28 def ensure_schema_is_not_empty!(schema_content) return unless schema_content.to_s.strip.empty? raise ConfigurationError, "Schema content is empty. Cannot proceed without database schema context." end |
#load_schema_content ⇒ String
Loads the database schema content from the configured path. Falls back to db/structure.sql if the primary schema file is not found.
15 16 17 18 19 20 21 22 |
# File 'lib/asktive_record/schema_loader.rb', line 15 def load_schema_content path = AsktiveRecord.configuration.db_schema_path return File.read(path) if File.exist?(path) attempt_schema_fallback(path) rescue SystemCallError => e raise ConfigurationError, "Error reading schema file at #{path}: #{e.}" end |
#validate_llm_api_key! ⇒ Object
Validates that the LLM API key is configured.
38 39 40 41 42 |
# File 'lib/asktive_record/schema_loader.rb', line 38 def validate_llm_api_key! return if AsktiveRecord.configuration&.llm_api_key raise ConfigurationError, "LLM API key is not configured for AsktiveRecord." end |