Module: Structify::Model
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/structify/model.rb
Overview
The Model module provides a DSL for defining LLM extraction schemas in your Rails models. It allows you to define fields, versioning, and validation for LLM-based data extraction.
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#saved_change_to_extracted_data? ⇒ Boolean
Check if the extracted data has been changed since the record was last saved Respects the default_container_attribute configuration.
-
#stored_version ⇒ Object
Get the stored version of this record.
-
#version_compatible_with?(required_version) ⇒ Boolean
Instance methods.
-
#version_in_range?(version, range) ⇒ Boolean
Check if a version is within a given range/array of versions This is used in field accessors to check version compatibility.
Instance Method Details
#saved_change_to_extracted_data? ⇒ Boolean
Check if the extracted data has been changed since the record was last saved Respects the default_container_attribute configuration
This provides a consistent method to check for changes regardless of the container attribute name that was configured.
59 60 61 62 63 |
# File 'lib/structify/model.rb', line 59 def saved_change_to_extracted_data? container_attribute = self.class.attr_json_config.default_container_attribute respond_to?("saved_change_to_#{container_attribute}?") && self.send("saved_change_to_#{container_attribute}?") end |
#stored_version ⇒ Object
Get the stored version of this record
46 47 48 49 50 |
# File 'lib/structify/model.rb', line 46 def stored_version container_attribute = self.class.attr_json_config.default_container_attribute record_data = self.send(container_attribute) || {} record_data["version"] || 1 end |
#version_compatible_with?(required_version) ⇒ Boolean
Instance methods
38 39 40 41 42 43 |
# File 'lib/structify/model.rb', line 38 def version_compatible_with?(required_version) container_attribute = self.class.attr_json_config.default_container_attribute record_data = self.send(container_attribute) || {} record_version = record_data["version"] || 1 record_version >= required_version end |
#version_in_range?(version, range) ⇒ Boolean
Check if a version is within a given range/array of versions This is used in field accessors to check version compatibility
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/structify/model.rb', line 71 def version_in_range?(version, range) case range when Range range.cover?(version) when Array range.include?(version) else version == range end end |