Class: ActiveRecord::ConnectionAdapters::EnsuredTable
- Defined in:
- lib/ensured_schema/ensured_table.rb
Instance Method Summary collapse
- #build_column_definition(column_name, column_type, options = {}) ⇒ Object
- #column(column_name, type, options = {}) ⇒ Object
- #define_columns(column_type, *args) ⇒ Object
- #remove(column_name) ⇒ Object
Methods inherited from Table
Instance Method Details
#build_column_definition(column_name, column_type, options = {}) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ensured_schema/ensured_table.rb', line 38 def build_column_definition(column_name, column_type, = {}) column = ColumnDefinition.new(@base, column_name, column_type) if [:limit] column.limit = [:limit] elsif native[column_type.to_sym].is_a?(Hash) column.limit = native[column_type.to_sym][:limit] end column.precision = [:precision] column.scale = [:scale] column.default = [:default] column.null = [:null] column end |
#column(column_name, type, options = {}) ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'lib/ensured_schema/ensured_table.rb', line 5 def column(column_name, type, = {}) if column_exists?(column_name) unless column_exists?(column_name, type, ) change(column_name, type, ) end else @base.add_column(@table_name, column_name, type, ) end end |
#define_columns(column_type, *args) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/ensured_schema/ensured_table.rb', line 27 def define_columns(column_type, *args) = args. column_names = args column_names.each do |name| column_def = build_column_definition(name, column_type, ) = column_def.members.inject({}){|h, k| h[k.to_sym] = column_def[k]; h;} column(name, column_type.to_sym, ) end end |
#remove(column_name) ⇒ Object
15 16 17 |
# File 'lib/ensured_schema/ensured_table.rb', line 15 def remove(column_name) super if column_exists?(column_name) end |