Class: MigrationValidators::Spec::Support::ColumnWrapper
- Inherits:
-
Object
- Object
- MigrationValidators::Spec::Support::ColumnWrapper
- Defined in:
- lib/migration_validators/spec/support/column_wrapper.rb
Instance Attribute Summary collapse
-
#column_name ⇒ Object
Returns the value of attribute column_name.
-
#last_exception ⇒ Object
Returns the value of attribute last_exception.
Instance Method Summary collapse
- #drop ⇒ Object
-
#initialize(column_name, table_wrapper, db) ⇒ ColumnWrapper
constructor
A new instance of ColumnWrapper.
- #insert(*values) ⇒ Object
- #to_array(values) ⇒ Object
- #update(*values) ⇒ Object
Constructor Details
#initialize(column_name, table_wrapper, db) ⇒ ColumnWrapper
Returns a new instance of ColumnWrapper.
10 11 12 13 14 |
# File 'lib/migration_validators/spec/support/column_wrapper.rb', line 10 def initialize column_name, table_wrapper, db @column_name = column_name @table_wrapper = table_wrapper @db = db end |
Instance Attribute Details
#column_name ⇒ Object
Returns the value of attribute column_name.
7 8 9 |
# File 'lib/migration_validators/spec/support/column_wrapper.rb', line 7 def column_name @column_name end |
#last_exception ⇒ Object
Returns the value of attribute last_exception.
8 9 10 |
# File 'lib/migration_validators/spec/support/column_wrapper.rb', line 8 def last_exception @last_exception end |
Instance Method Details
#drop ⇒ Object
16 17 18 |
# File 'lib/migration_validators/spec/support/column_wrapper.rb', line 16 def drop @db.remove_column @table_wrapper.table_name, column_name end |
#insert(*values) ⇒ Object
26 27 28 29 30 |
# File 'lib/migration_validators/spec/support/column_wrapper.rb', line 26 def insert *values @last_exception = nil to_array(values).each {|value| execute(value, "INSERT INTO #{@table_wrapper.table_name}(#{column_name}) VALUES(#{value})")} self end |
#to_array(values) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/migration_validators/spec/support/column_wrapper.rb', line 32 def to_array values values.collect do |value| case value.class.name when "Range" then to_array(value.to_a) when "Array" then to_array(value) when "String" then ['NULL', "''"].include?(value.upcase) ? value : quote(value) when "Date" then quote(value.strftime('%Y-%m-%d')) when "Time" then quote(value.strftime('%Y-%m-%d %H:%M:%S')) when "DateTime" then quote(value.strftime('%Y-%m-%d %H:%M:%S')) when "NilClass" then 'NULL' else value end end.flatten end |
#update(*values) ⇒ Object
20 21 22 23 24 |
# File 'lib/migration_validators/spec/support/column_wrapper.rb', line 20 def update *values @last_exception = nil to_array(values).each{|value| execute(value, "UPDATE #{@table_wrapper.table_name} SET #{column_name} = #{value}")} self end |