Class: MassInsert::Builder::Adapters::Helpers::ColumnValue
- Inherits:
-
Object
- Object
- MassInsert::Builder::Adapters::Helpers::ColumnValue
- Defined in:
- lib/mass_insert/builder/adapters/helpers/column_value.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
Returns the value of attribute class_name.
-
#column ⇒ Object
Returns the value of attribute column.
-
#row ⇒ Object
Returns the value of attribute row.
Instance Method Summary collapse
-
#build ⇒ Object
Returns the valid column value to be included in the query.
-
#column_type ⇒ Object
Returns a symbol with the column type according to the database.
-
#column_value ⇒ Object
Returns the value to this column in the row hash.
-
#column_value_boolean ⇒ Object
Returns the correct value to boolean column.
-
#column_value_decimal ⇒ Object
(also: #column_value_float)
Returns the correct value to decimal or float column.
-
#column_value_integer ⇒ Object
Returns the correct value to integer column.
-
#column_value_string ⇒ Object
(also: #column_value_text, #column_value_date, #column_value_time, #column_value_datetime, #column_value_timestamp, #column_value_binary)
Returns the correct value when column value is string, text, date, time, datetime, timestamp.
-
#default_db_value ⇒ Object
Returns the default database column value using methods that ActiveRecord provides.
-
#default_value ⇒ Object
Returns the default column value and it’s added to the query if the row hash does not contains column value.
-
#initialize(row, column, class_name) ⇒ ColumnValue
constructor
A new instance of ColumnValue.
-
#mysql2_column_value_boolean ⇒ Object
(also: #postgresql_column_value_boolean)
Returns the column value to boolean column to mysql, postgresql and sqlserver databases.
-
#sqlite3_column_value_boolean ⇒ Object
(also: #sqlserver_column_value_boolean)
Returns the column value to boolean column to sqlite database.
Constructor Details
#initialize(row, column, class_name) ⇒ ColumnValue
Returns a new instance of ColumnValue.
9 10 11 12 13 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 9 def initialize row, column, class_name @row = row @column = column @class_name = class_name end |
Instance Attribute Details
#class_name ⇒ Object
Returns the value of attribute class_name.
7 8 9 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 7 def class_name @class_name end |
#column ⇒ Object
Returns the value of attribute column.
7 8 9 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 7 def column @column end |
#row ⇒ Object
Returns the value of attribute row.
7 8 9 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 7 def row @row end |
Instance Method Details
#build ⇒ Object
Returns the valid column value to be included in the query. The value depends of the database engine.
40 41 42 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 40 def build column_value.nil? ? default_value : send(:"column_value_#{column_type}") end |
#column_type ⇒ Object
Returns a symbol with the column type according to the database.
16 17 18 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 16 def column_type class_name.columns_hash[@column.to_s].type end |
#column_value ⇒ Object
Returns the value to this column in the row hash. The value is finding by symbol or string key to be most flexible.
22 23 24 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 22 def column_value row.fetch(column){row[@column.to_s]} end |
#column_value_boolean ⇒ Object
Returns the correct value to boolean column. This column calls the correct method according to the database adapter.
69 70 71 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 69 def column_value_boolean self.send(:"#{Utilities.adapter}_column_value_boolean") end |
#column_value_decimal ⇒ Object Also known as: column_value_float
Returns the correct value to decimal or float column.
62 63 64 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 62 def column_value_decimal column_value.to_f.to_s end |
#column_value_integer ⇒ Object
Returns the correct value to integer column.
57 58 59 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 57 def column_value_integer column_value.to_i.to_s end |
#column_value_string ⇒ Object Also known as: column_value_text, column_value_date, column_value_time, column_value_datetime, column_value_timestamp, column_value_binary
Returns the correct value when column value is string, text, date, time, datetime, timestamp.
46 47 48 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 46 def column_value_string "'#{column_value}'" end |
#default_db_value ⇒ Object
Returns the default database column value using methods that ActiveRecord provides.
34 35 36 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 34 def default_db_value class_name.columns_hash[@column.to_s].default end |
#default_value ⇒ Object
Returns the default column value and it’s added to the query if the row hash does not contains column value.
28 29 30 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 28 def default_value default_db_value ? default_db_value.to_s : "null" end |
#mysql2_column_value_boolean ⇒ Object Also known as: postgresql_column_value_boolean
Returns the column value to boolean column to mysql, postgresql and sqlserver databases.
75 76 77 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 75 def mysql2_column_value_boolean column_value ? "true" : "false" end |
#sqlite3_column_value_boolean ⇒ Object Also known as: sqlserver_column_value_boolean
Returns the column value to boolean column to sqlite database.
81 82 83 |
# File 'lib/mass_insert/builder/adapters/helpers/column_value.rb', line 81 def sqlite3_column_value_boolean column_value ? "1" : "0" end |