class Ryakuzu::ColumnDefaultService

Attributes

column[R]
default[R]
index[R]
null[R]
old_default[R]
old_null[R]
old_type[R]
parameters[R]
params[R]
table[R]
type[R]

Public Class Methods

new(params) click to toggle source
# File lib/ryakuzu/services/column_default_service.rb, line 6
def initialize(params)
  @params      = params
  @parameters  = params['parameters']
  @default     = params['default']
  @index       = params['index']
  @null        = params['null']
  @type        = params['type']
  @table       = params['table']
  @column      = params['column']
  @old_type    = params['parameters'][':old_type']
  @old_default = params['parameters'][':old_default']
end

Public Instance Methods

call() click to toggle source
# File lib/ryakuzu/services/column_default_service.rb, line 19
def call
  processing_params
  hash = to_hash(params)

  type, old_type, default, old_default = *hash.values

  run_full(type, default)        if type != old_type && default != old_default
  run_type(type, old_default)    if type != old_type && default == old_default
  run_default(old_type, default) if default != old_default && type == old_type
end

Private Instance Methods

processing_params() click to toggle source
# File lib/ryakuzu/services/column_default_service.rb, line 32
def processing_params
  @default     = '' if default == "\"\""
  @old_default = '' if old_default == "\"\""
  type.gsub!('Current: ', '')
end
run_default(old_type, default) click to toggle source
# File lib/ryakuzu/services/column_default_service.rb, line 54
def run_default(old_type, default)
  text = MigrationText.new(table, column, old_type, default).default_migration
  Ryakuzu::RunMigration.new(table: table, column: column).call(column, text, 'column')
end
run_full(type, default) click to toggle source
# File lib/ryakuzu/services/column_default_service.rb, line 44
def run_full(type, default)
  text = MigrationText.new(table, column, type, default).full_migration
  Ryakuzu::RunMigration.new(table: table, column: column).call(column, text, 'column')
end
run_type(type, old_default) click to toggle source
# File lib/ryakuzu/services/column_default_service.rb, line 49
def run_type(type, old_default)
  text = MigrationText.new(table, column, type, old_default).type_migration
  Ryakuzu::RunMigration.new(table: table, column: column).call(column, text, 'column')
end
to_hash(param) click to toggle source
# File lib/ryakuzu/services/column_default_service.rb, line 38
def to_hash(param)
  current = param.reject { |k, _v| %w(table column).include? k }.except('parameters')
  zip     = current.zip(params['parameters'])
  Hash[*zip.flatten]
end