Class: DeviseScim::Generators::InstallGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



24
25
26
# File 'lib/generators/devise_scim/install_generator.rb', line 24

def self.next_migration_number(dirname)
  ActiveRecord::Generators::Base.next_migration_number(dirname)
end

Instance Method Details

#copy_initializerObject



65
66
67
# File 'lib/generators/devise_scim/install_generator.rb', line 65

def copy_initializer
  template "devise_scim.rb.tt", "config/initializers/devise_scim.rb"
end

#copy_tenant_migrationsObject



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/generators/devise_scim/install_generator.rb', line 53

def copy_tenant_migrations
  return unless options[:multi_tenant]

  if options[:tenant_model]
    migration_template "add_scim_to_tenant.rb.tt",
                       "db/migrate/add_scim_to_#{tenant_table_name}.rb"
  else
    migration_template "create_scim_tenants.rb.tt", "db/migrate/create_scim_tenants.rb"
  end
  migration_template "create_scim_tenant_users.rb.tt", "db/migrate/create_scim_tenant_users.rb"
end

#copy_user_migrationObject



46
47
48
49
50
51
# File 'lib/generators/devise_scim/install_generator.rb', line 46

def copy_user_migration
  migration_template(
    "add_scim_to_users.rb.tt",
    "db/migrate/add_scim_to_#{table_name}.rb"
  )
end

#preflight_checkObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/generators/devise_scim/install_generator.rb', line 28

def preflight_check
  return unless needs_doorkeeper?

  unless doorkeeper_in_gemfile?
    say_status :error, "Doorkeeper gem not found in Gemfile.", :red
    say "  Add `gem 'doorkeeper', '~> 5.6'` to your Gemfile and run `bundle install`.", :red
    raise Thor::Error, "Aborting: Doorkeeper required for #{doorkeeper_reason}."
  end

  return if doorkeeper_installed?

  unless yes?("Doorkeeper not yet installed. Run `rails g doorkeeper:install` now?")
    raise Thor::Error, "Aborting. Run `rails g doorkeeper:install` before proceeding."
  end

  generate "doorkeeper:install"
end