Class: MigrationDefs::CreateTableOption

Inherits:
AbstractMigrationClass show all
Defined in:
lib/migration_defs.rb

Constant Summary collapse

Description =
{
  'id' => '主キーを自動生成',
  'primary_key' => '主キーのカラムの名前',
  'options' => 'テーブルオプション',
  'temporary' => '一時テーブルとして作成',
  'force' => 'テーブルを作成前に、既存のテーブルを削除',
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id = true, primary_key = 'id', options = nil, temporary = false, force = false) ⇒ CreateTableOption

Returns a new instance of CreateTableOption.



231
232
233
234
235
236
237
# File 'lib/migration_defs.rb', line 231

def initialize(id = true, primary_key = 'id', options = nil, temporary = false, force = false)
  @id = id
  @primary_key = primary_key
  @options = options
  @temporary = temporary
  @force = force
end

Instance Attribute Details

#forceObject

Returns the value of attribute force.



221
222
223
# File 'lib/migration_defs.rb', line 221

def force
  @force
end

#idObject

Returns the value of attribute id.



221
222
223
# File 'lib/migration_defs.rb', line 221

def id
  @id
end

#optionsObject

Returns the value of attribute options.



221
222
223
# File 'lib/migration_defs.rb', line 221

def options
  @options
end

#primary_keyObject

Returns the value of attribute primary_key.



221
222
223
# File 'lib/migration_defs.rb', line 221

def primary_key
  @primary_key
end

#temporaryObject

Returns the value of attribute temporary.



221
222
223
# File 'lib/migration_defs.rb', line 221

def temporary
  @temporary
end

Instance Method Details

#get_strObject



254
255
256
257
258
259
260
261
262
# File 'lib/migration_defs.rb', line 254

def get_str
  result = ''
  result += ", :id => #{@id.to_s}" if !@id.nil? && !@id
  result += ", :primary_key => #{@primary_key}" if @primary_key != 'id'
  result += ", :options => #{@options}" if !@options.nil? && !@options.blank?
  result += ", :temporary => #{@temporary.to_s}" if !@temporary.nil? && @temporary != false
  result += ", :force => #{@force.to_s}" if !@force.nil? && @force != true
  result
end

#set_option(key, val) ⇒ Object



239
240
241
242
243
244
245
246
247
248
249
250
251
252
# File 'lib/migration_defs.rb', line 239

def set_option(key, val)
  case key
  when 'id'
    @id = (val == 'true')
  when 'primary_key'
    @primary_key = val
  when 'options'
    @options = val
  when 'temporary'
    @temporary = (val == 'true')
  when 'force'
    @force = (val == 'true')
  end
end