Class: EasyTalk::ActiveRecordSchemaBuilder
- Inherits:
-
Object
- Object
- EasyTalk::ActiveRecordSchemaBuilder
- Defined in:
- lib/easy_talk/active_record_schema_builder.rb
Overview
This class is responsible for building a SchemaDefinition from an ActiveRecord model It analyzes the database schema and creates a SchemaDefinition that can be passed to ObjectBuilder for final schema generation
Constant Summary collapse
- COLUMN_TYPE_MAP =
Mapping of ActiveRecord column types to Ruby classes
{ string: String, text: String, integer: Integer, bigint: Integer, float: Float, decimal: Float, boolean: T::Boolean, date: Date, datetime: DateTime, timestamp: DateTime, time: Time, json: Hash, jsonb: Hash }.freeze
- FORMAT_MAP =
Mapping for format constraints based on column type
{ date: 'date', datetime: 'date-time', timestamp: 'date-time', time: 'time' }.freeze
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
-
#build_schema_definition ⇒ EasyTalk::SchemaDefinition
Build a SchemaDefinition object from the ActiveRecord model.
-
#initialize(model) ⇒ ActiveRecordSchemaBuilder
constructor
Initialize the builder with an ActiveRecord model.
Constructor Details
#initialize(model) ⇒ ActiveRecordSchemaBuilder
Initialize the builder with an ActiveRecord model
39 40 41 42 43 |
# File 'lib/easy_talk/active_record_schema_builder.rb', line 39 def initialize(model) raise ArgumentError, 'Class must be an ActiveRecord model' unless model.ancestors.include?(ActiveRecord::Base) @model = model end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
33 34 35 |
# File 'lib/easy_talk/active_record_schema_builder.rb', line 33 def model @model end |
Instance Method Details
#build_schema_definition ⇒ EasyTalk::SchemaDefinition
Build a SchemaDefinition object from the ActiveRecord model
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/easy_talk/active_record_schema_builder.rb', line 48 def build_schema_definition schema_def = SchemaDefinition.new(model.name) # Apply basic schema metadata (schema_def) # Add all database columns as properties add_column_properties(schema_def) # Add model associations as properties add_association_properties(schema_def) unless EasyTalk.configuration.exclude_associations # Add virtual properties defined in schema_enhancements add_virtual_properties(schema_def) schema_def end |