Class: DbFuel::Modeling::KeyedColumn
- Inherits:
-
Object
- Object
- DbFuel::Modeling::KeyedColumn
- 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
-
#column ⇒ Object
readonly
Returns the value of attribute column.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Instance Method Summary collapse
-
#initialize(key:, column: '') ⇒ KeyedColumn
constructor
A new instance of KeyedColumn.
Constructor Details
#initialize(key:, column: '') ⇒ KeyedColumn
Returns a new instance of KeyedColumn.
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
#column ⇒ Object (readonly)
Returns the value of attribute column.
18 19 20 |
# File 'lib/db_fuel/modeling/keyed_column.rb', line 18 def column @column end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
18 19 20 |
# File 'lib/db_fuel/modeling/keyed_column.rb', line 18 def key @key end |