Class: AssociationGenerator

Inherits:
ActiveRecord::Generators::Base
  • Object
show all
Defined in:
lib/generators/association/association_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_role_migrationObject



7
8
9
10
11
12
13
# File 'lib/generators/association/association_generator.rb', line 7

def copy_role_migration
	if (behavior == :invoke && model_exists?("role")) || (behavior == :revoke && role_migration_exists?)
    migration_template "role_migration_existing.rb", "db/migrate/add_name_to_roles.rb", migration_version: migration_version
  else
    migration_template "role_migration.rb", "db/migrate/create_roles.rb", migration_version: migration_version
  end
end

#copy_role_modelObject



23
24
25
26
27
28
29
# File 'lib/generators/association/association_generator.rb', line 23

def copy_role_model
  if model_exists?("role")
    copy_file "role_model_existing.rb","app/models/role.rb"
  else
    copy_file "role_model.rb","app/models/role.rb"
  end
end

#copy_user_role_modelObject



31
32
33
34
35
36
37
# File 'lib/generators/association/association_generator.rb', line 31

def copy_user_role_model
  if model_exists?("user_role")
    copy_file "user_role_model_existing.rb","app/models/user_role.rb"
  else
    copy_file "user_role_model.rb","app/models/user_role.rb"
  end
end

#copy_user_roles_migrationObject



15
16
17
18
19
20
21
# File 'lib/generators/association/association_generator.rb', line 15

def copy_user_roles_migration
	if (behavior == :invoke && model_exists?("user_role")) || (behavior == :revoke && user_role_migration_exists?)
    migration_template "user_role_migration_existing.rb", "db/migrate/add_user_roles_association_to_user_roles.rb", migration_version: migration_version
  else
    migration_template "user_role_migration.rb", "db/migrate/create_user_roles.rb", migration_version: migration_version
  end
end