Class: ActiveRecord::Generators::GrapeBunchGenerator

Inherits:
Base
  • Object
show all
Includes:
GrapeBunch::Generators::OrmHelpers
Defined in:
lib/generators/active_record/grape_bunch_generator.rb

Instance Method Summary collapse

Methods included from GrapeBunch::Generators::OrmHelpers

#migration_exists?, #migration_path, #model_exists?, #model_path

Instance Method Details

#copy_grape_bunch_migrationObject



13
14
15
16
17
18
19
# File 'lib/generators/active_record/grape_bunch_generator.rb', line 13

def copy_grape_bunch_migration
  if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))
    migration_template "migration_existing.rb", "db/migrate/add_grape_bunch_to_#{table_name}.rb", migration_version: migration_version
  else
    migration_template "migration.rb", "db/migrate/grape_bunch_create_#{table_name}.rb", migration_version: migration_version
  end
end

#generate_modelObject



21
22
23
# File 'lib/generators/active_record/grape_bunch_generator.rb', line 21

def generate_model
  invoke "active_record:model", [name], migration: false unless model_exists? && behavior == :invoke
end

#migration_dataObject



25
26
27
28
29
# File 'lib/generators/active_record/grape_bunch_generator.rb', line 25

def migration_data
<<RUBY
t.string :email,              null: false, default: ""
RUBY
end

#migration_versionObject



36
37
38
39
40
# File 'lib/generators/active_record/grape_bunch_generator.rb', line 36

def migration_version
  if rails5?
    "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
  end
end

#rails5?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/generators/active_record/grape_bunch_generator.rb', line 31

def rails5?
  Rails.version.start_with? '5'
end