Sha256: 8ac5e9dd1e5c8eb771495628a77f5fbbcffcb13fe009e3a65474468086832783

Contents?: true

Size: 1.71 KB

Versions: 5

Compression:

Stored size: 1.71 KB

Contents

module Stationed
  module Generators
    module Plugins
      module Devise
        def self.prepended(base)
          base.class_option :devise,
            type: :boolean,
            default: true,
            desc: 'Set up authentication with Devise'
        end

        def finish_template
          return super unless options[:devise]
          gem 'devise'
          copy_file 'devise.rb', 'spec/support/devise.rb' if options[:rspec]
          route "devise_scope :user do\n    root to: 'devise/sessions#new'\n  end\n"
          environment nil, env: :test do
            "# Set default url options for Devise mailers\n  config.action_mailer.default_url_options = { host: 'example.com' }\n"
          end
          environment nil, env: :development do
            "# Set default url options for Devise mailers\n  config.action_mailer.default_url_options = { host: 'localhost:3000' }\n"
          end
          super
        end

        def run_bundle
          super
          return unless options[:devise]
          generate 'devise:install'
          generate 'devise user'
          return unless options[:pundit]
          application do
            <<-RUBY
# Let Pundit authorization or custom responders not influence the workings
    # of Devise.
    config.to_prepare do
      [
        Devise::SessionsController,
        Devise::RegistrationsController,
        Devise::PasswordsController
      ].each do |devise_controller_class|
        devise_controller_class.skip_after_action :verify_authorized
        devise_controller_class.skip_after_action :verify_policy_scoped
        devise_controller_class.responder = ActionController::Responder
      end
    end
            RUBY
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
stationed-0.6.0 lib/stationed/generators/plugins/devise.rb
stationed-0.5.0 lib/stationed/generators/plugins/devise.rb
stationed-0.4.0 lib/stationed/generators/plugins/devise.rb
stationed-0.3.0 lib/stationed/generators/plugins/devise.rb
stationed-0.2.0 lib/stationed/generators/plugins/devise.rb