class Mi::Generators::CreateGenerator

Public Instance Methods

doing() click to toggle source
# File lib/generators/mi/create_generator.rb, line 11
def doing
  migration_template('create.rb.erb', "db/migrate/#{destination}.rb")
end

Private Instance Methods

destination() click to toggle source
# File lib/generators/mi/create_generator.rb, line 46
def destination
  "create_#{table_name}_table"
end
table_name() click to toggle source

when create table, table name is only one.

# File lib/generators/mi/create_generator.rb, line 39
def table_name
  @table_name ||= (
    table, = *arg_groups.first
    table.tableize
  )
end
to_method(col) click to toggle source

returns t.TYPE :NAME, OPTIONS: true e.g.) t.string :email

# File lib/generators/mi/create_generator.rb, line 23
def to_method(col)
  info = parse_column(col)
  # TODO: when type is not specified, migration file would be created.
  raise TypeIsRequired, "When mi:create, type is required. Please specify type like `#{info[:name]}:TYPE`" unless info[:type]
  raise NotAllowMethod, "#{info[:method]} is not allowed. You can only use `+` when `mi:create`" unless info[:method] == '+'

  res = "t.#{info[:type]} :#{info[:name]}"

  return res unless info[:options]
  # TODO: DRY
  res << ", #{info[:options][1..-2].gsub(':', ': ').gsub(',', ', ')}"

  res
end