Class: Ea::Qea::Models::BaseModel
- Inherits:
-
Lutaml::Model::Serializable
- Object
- Lutaml::Model::Serializable
- Ea::Qea::Models::BaseModel
- Defined in:
- lib/ea/qea/models/base_model.rb
Direct Known Subclasses
EaAttribute, EaAttributeTag, EaComplexityType, EaConnector, EaConnectorType, EaConstraintType, EaDatatype, EaDiagram, EaDiagramLink, EaDiagramObject, EaDiagramType, EaDocument, EaObject, EaObjectConstraint, EaObjectProperty, EaObjectType, EaOperation, EaOperationParam, EaPackage, EaScript, EaStatusType, EaStereotype, EaTaggedValue, EaXref
Class Method Summary collapse
-
.column_map ⇒ Hash<String, Symbol>
Map of EA database column names to Ruby attribute names.
-
.from_db_row(row) ⇒ BaseModel?
Create instance from database row hash.
- .primary_key_column ⇒ Object
- .table_name ⇒ Object
Instance Method Summary collapse
- #primary_key ⇒ Object
-
#sort_position ⇒ Integer
Stable sort key used by transformers that need to emit children in EA's tree-position order.
Class Method Details
.column_map ⇒ Hash<String, Symbol>
Map of EA database column names to Ruby attribute names. Subclasses override this for non-trivial mappings.
34 35 36 |
# File 'lib/ea/qea/models/base_model.rb', line 34 def self.column_map {} end |
.from_db_row(row) ⇒ BaseModel?
Create instance from database row hash. Uses column_map for explicit mappings, falls back to lowercase.
42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ea/qea/models/base_model.rb', line 42 def self.from_db_row(row) return nil if row.nil? mapping = column_map attrs = row.transform_keys do |key| if mapping.key?(key) mapping[key] else key.to_s.downcase.to_sym end end new(attrs) end |
.primary_key_column ⇒ Object
9 10 11 12 |
# File 'lib/ea/qea/models/base_model.rb', line 9 def self.primary_key_column raise NotImplementedError, "#{self} must implement .primary_key_column" end |
.table_name ⇒ Object
14 15 16 17 |
# File 'lib/ea/qea/models/base_model.rb', line 14 def self.table_name raise NotImplementedError, "#{self} must implement .table_name" end |
Instance Method Details
#primary_key ⇒ Object
19 20 21 |
# File 'lib/ea/qea/models/base_model.rb', line 19 def primary_key public_send(self.class.primary_key_column) end |
#sort_position ⇒ Integer
Stable sort key used by transformers that need to emit children in
EA's tree-position order. Subclasses with a different field name
(e.g., pos on t_attribute rows) override this.
27 28 29 |
# File 'lib/ea/qea/models/base_model.rb', line 27 def sort_position 0 end |