Class: DbFuel::Modeling::KeyedColumn

Inherits:
Object
  • Object
show all
Defined in:
lib/db_fuel/modeling/keyed_column.rb

Overview

Connects a hash key to a SQL column. By default if a column is not given then its key will be used for both. The general use case for this is for mapping objects to SQL and SQL to objects.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, column: '') ⇒ KeyedColumn

Returns a new instance of KeyedColumn.

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
# File 'lib/db_fuel/modeling/keyed_column.rb', line 20

def initialize(key:, column: '')
  raise ArgumentError, 'key is required' if key.blank?

  @column = column.present? ? column.to_s : key.to_s
  @key    = key.to_s

  freeze
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



18
19
20
# File 'lib/db_fuel/modeling/keyed_column.rb', line 18

def column
  @column
end

#keyObject (readonly)

Returns the value of attribute key.



18
19
20
# File 'lib/db_fuel/modeling/keyed_column.rb', line 18

def key
  @key
end