Class: Teamable::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Includes:
ActiveRecord::Generators::Migration
Defined in:
lib/generators/teamable/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#add_routeObject



39
40
41
# File 'lib/generators/teamable/install_generator.rb', line 39

def add_route
  route 'teamable "team"'
end

#check_install_requirementsObject



14
15
16
17
18
19
20
# File 'lib/generators/teamable/install_generator.rb', line 14

def check_install_requirements
  return if user_model_exists?

  say "Teamable requires a User model to be present before you continue with the install", :red
  say "Learn more at: https://github.com/kiqr/teamable#getting-started", :red
  raise Teamable::InvalidUserModel, "Missing file: #{user_model_path}"
end

#generate_migrationsObject



33
34
35
36
37
# File 'lib/generators/teamable/install_generator.rb', line 33

def generate_migrations
  migration_template "migrations/account.tt", "#{db_migrate_path}/teamable_create_accounts.rb"
  migration_template "migrations/member.tt", "#{db_migrate_path}/teamable_create_members.rb"
  migration_template "migrations/user.tt", "#{db_migrate_path}/teamable_add_personal_account_to_users.rb"
end

#generate_modelsObject



28
29
30
31
# File 'lib/generators/teamable/install_generator.rb', line 28

def generate_models
  template "models/account.tt", "app/models/account.rb"
  template "models/member.tt", "app/models/member.rb"
end

#inject_into_user_modelObject



22
23
24
25
26
# File 'lib/generators/teamable/install_generator.rb', line 22

def inject_into_user_model
  inject_into_class user_model_path, "User" do
    "  include Teamable::Models::User\n"
  end
end