Class: Ea::Qea::Models::BaseModel

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/ea/qea/models/base_model.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.column_mapHash<String, Symbol>

Map of EA database column names to Ruby attribute names. Subclasses override this for non-trivial mappings.

Returns:

  • (Hash<String, Symbol>)


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.

Parameters:

  • row (Hash)

    database row with string keys

Returns:



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_columnObject

Raises:

  • (NotImplementedError)


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_nameObject

Raises:

  • (NotImplementedError)


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_keyObject



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_positionInteger

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.

Returns:

  • (Integer)


27
28
29
# File 'lib/ea/qea/models/base_model.rb', line 27

def sort_position
  0
end