Class: LocalizableDb::Generators::ModelGenerator

Inherits:
ActiveRecord::Generators::ModelGenerator
  • Object
show all
Includes:
OrmHelper
Defined in:
lib/generators/localizable_db/model_generator.rb

Instance Method Summary collapse

Methods included from Languages

config

Instance Method Details

#create_migration_fileObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/generators/localizable_db/model_generator.rb', line 19

def create_migration_file
  return unless options[:migration] && options[:parent].nil?

  attributes.each { |a|
    a.attr_options.delete(:index) if a.reference? && !a.has_index?
  } if options[:indexes] == false

  model_template = "#{__FILE__}/../templates/create_table_migration.rb"
  model_migration_name =
    "db/migrate/create_#{table_name}.rb"

  migration_template(
    model_template, model_migration_name,
    migration_version: migration_version
  )
end

#generate_migration_for_localizableObject



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/generators/localizable_db/model_generator.rb', line 36

def generate_migration_for_localizable
  case behavior
  when :invoke
    invoke(
      "localizable_db:migration",
      [
        table_name.singularize.camelize
      ] +
      attributes.map { |attribute|
        if attribute.type.eql? :string
          "#{attribute.name}:#{attribute.type.to_s}"
        end
      }
    )
  when :revoke
    invoke(
      "localizable_db:migration",
      [ table_name ], behavior: :revoke
    )
  end
end