Class: ActiveRecord::Generators::GrapeBunchGenerator
Instance Method Summary
collapse
#migration_exists?, #migration_path, #model_exists?, #model_path
Instance Method Details
#copy_grape_bunch_migration ⇒ Object
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_model ⇒ Object
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_data ⇒ Object
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_version ⇒ Object
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
31
32
33
|
# File 'lib/generators/active_record/grape_bunch_generator.rb', line 31
def rails5?
Rails.version.start_with? '5'
end
|