Sha256: e794cbcedd2a3df540dace354aa92a2d9309e804c508ceefa3df55614be49553

Contents?: true

Size: 1.51 KB

Versions: 21

Compression:

Stored size: 1.51 KB

Contents

class Recipes::Devise < Rails::AppBuilder
  def ask
    use_devise = answer(:devise) do
      Ask.confirm "Do you want to use Devise for authentication? (required for ActiveAdmin)"
    end

    if use_devise
      set(:authentication, use_devise)
      ask_for_devise_model
    end
  end

  def create
    add_devise if selected?(:authentication)
  end

  def install
    ask_for_devise_model
    add_devise
  end

  def installed?
    gem_exists?(/devise/)
  end

  private

  def ask_for_devise_model
    create_user_model = answer(:"devise-user-model") do
      Ask.confirm "Do you want to create a user model for Devise?"
    end

    set(:authentication_model, :user) if create_user_model
  end

  def add_devise
    gather_gem 'devise'
    gather_gem 'devise-i18n'

    after(:gem_install) do
      generate "devise:install"

      if auth_model = get(:authentication_model)
        generate "devise #{auth_model}"
      end

      gsub_file "config/initializers/devise.rb", /(\# config.secret_key.+)/i do |_match|
        "config.secret_key = ENV['DEVISE_SECRET_KEY']"
      end

      gsub_file "config/initializers/devise.rb", /(config.mailer_sender.+)/i do |_match|
        "config.mailer_sender = ENV['DEFAULT_EMAIL_ADDRESS']"
      end

      gsub_file "config/initializers/devise.rb", /(\# config.pepper.+)/i do |_match|
        "# config.pepper = 'onhcylrat7x8bjyr5o15sxaix3vbu0sl'"
      end

      append_to_file '.env.development', "DEVISE_SECRET_KEY=\n"
      add_readme_section :internal_dependencies, :devise
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
potassium-7.2.0 lib/potassium/recipes/devise.rb
potassium-7.1.0 lib/potassium/recipes/devise.rb
potassium-7.0.0 lib/potassium/recipes/devise.rb
potassium-6.7.0 lib/potassium/recipes/devise.rb
potassium-6.6.0 lib/potassium/recipes/devise.rb
potassium-6.5.0 lib/potassium/recipes/devise.rb
potassium-6.4.0 lib/potassium/recipes/devise.rb
potassium-6.3.0 lib/potassium/recipes/devise.rb
potassium-6.2.0 lib/potassium/recipes/devise.rb
potassium-6.1.0 lib/potassium/recipes/devise.rb
potassium-6.0.0 lib/potassium/recipes/devise.rb
potassium-5.2.3 lib/potassium/recipes/devise.rb
potassium-5.2.2 lib/potassium/recipes/devise.rb
potassium-5.2.1 lib/potassium/recipes/devise.rb
potassium-5.2.0 lib/potassium/recipes/devise.rb
potassium-5.1.4 lib/potassium/recipes/devise.rb
potassium-5.1.3 lib/potassium/recipes/devise.rb
potassium-5.1.2 lib/potassium/recipes/devise.rb
potassium-5.1.1 lib/potassium/recipes/devise.rb
potassium-3.0.0 lib/potassium/recipes/devise.rb