Class: Toolchest::Generators::AuthGenerator

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.next_migration_number(dirname) ⇒ Object



12
# File 'lib/generators/toolchest/auth_generator.rb', line 12

def self.next_migration_number(dirname) = Time.now.utc.strftime("%Y%m%d%H%M%S")

Instance Method Details

#copy_migrationObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/generators/toolchest/auth_generator.rb', line 22

def copy_migration
  case strategy
  when "token"
    migration_template "create_toolchest_tokens.rb.tt",
      "db/migrate/create_toolchest_tokens.rb"
  when "oauth"
    migration_template "create_toolchest_oauth.rb.tt",
      "db/migrate/create_toolchest_oauth.rb"
  end
end


33
34
35
36
37
# File 'lib/generators/toolchest/auth_generator.rb', line 33

def create_consent_view
  return unless strategy == "oauth"
  template "oauth_authorize.html.erb.tt",
    "app/views/toolchest/oauth/authorizations/new.html.erb"
end

#update_initializerObject



39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/toolchest/auth_generator.rb', line 39

def update_initializer
  say ""
  say "Auth migration created for :#{strategy}.", :green
  say ""
  say "Update your initializer:"
  say "  config.auth = :#{strategy}"
  say ""
  say "Then run: rails db:migrate"
  say ""
end

#validate_strategyObject



16
17
18
19
20
# File 'lib/generators/toolchest/auth_generator.rb', line 16

def validate_strategy
  unless %w[token oauth].include?(strategy)
    raise Thor::Error, "Unknown auth strategy: #{strategy}. Use 'token' or 'oauth'."
  end
end