Class: Toolchest::Generators::AuthGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Toolchest::Generators::AuthGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/toolchest/auth_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #copy_migration ⇒ Object
- #create_consent_view ⇒ Object
- #update_initializer ⇒ Object
- #validate_strategy ⇒ Object
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_migration ⇒ Object
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 |
#create_consent_view ⇒ Object
33 34 35 36 37 |
# File 'lib/generators/toolchest/auth_generator.rb', line 33 def return unless strategy == "oauth" template "oauth_authorize.html.erb.tt", "app/views/toolchest/oauth/authorizations/new.html.erb" end |
#update_initializer ⇒ Object
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_strategy ⇒ Object
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 |