Class: Ryakuzu::MigrationText

Inherits:
Object
  • Object
show all
Defined in:
lib/ryakuzu/tools/migration_text.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(table, column, type, default) ⇒ MigrationText

Returns a new instance of MigrationText.



5
6
7
8
9
10
11
# File 'lib/ryakuzu/tools/migration_text.rb', line 5

def initialize(table, column, type, default)
  @table   = table
  @column  = column
  @type    = type
  @default = default
  @text    = "remove_column :#{@table.tableize}, :#{@column}\n"
end

Instance Attribute Details

#columnObject (readonly)

Returns the value of attribute column.



3
4
5
# File 'lib/ryakuzu/tools/migration_text.rb', line 3

def column
  @column
end

#defaultObject (readonly)

Returns the value of attribute default.



3
4
5
# File 'lib/ryakuzu/tools/migration_text.rb', line 3

def default
  @default
end

#tableObject (readonly)

Returns the value of attribute table.



3
4
5
# File 'lib/ryakuzu/tools/migration_text.rb', line 3

def table
  @table
end

#textObject (readonly)

Returns the value of attribute text.



3
4
5
# File 'lib/ryakuzu/tools/migration_text.rb', line 3

def text
  @text
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/ryakuzu/tools/migration_text.rb', line 3

def type
  @type
end

Instance Method Details

#default_migrationObject



21
22
23
24
# File 'lib/ryakuzu/tools/migration_text.rb', line 21

def default_migration
  val_def = create_full_text
  text.concat "add_column :#{table.tableize}, :#{column}, :#{type.downcase}, default: #{val_def}"
end

#full_migrationObject



13
14
15
# File 'lib/ryakuzu/tools/migration_text.rb', line 13

def full_migration
  default.empty? ? type_migration : default_migration
end

#type_migrationObject



17
18
19
# File 'lib/ryakuzu/tools/migration_text.rb', line 17

def type_migration
  text.concat "add_column :#{table.tableize}, :#{column}, :#{type.downcase}"
end