Sha256: 75a10bdf2671c49272a83ab999834ba03005383efb88c55ed412ca26029c0611

Contents?: true

Size: 1.52 KB

Versions: 26

Compression:

Stored size: 1.52 KB

Contents

require 'rails/generators/base'

module Devise
  module Generators
    class ControllersGenerator < Rails::Generators::Base
      CONTROLLERS = %w(confirmations passwords registrations sessions unlocks omniauth_callbacks).freeze

      desc <<-DESC.strip_heredoc
        Create inherited Devise controllers in your app/controllers folder.

        Use -c to specify which controller you want to overwrite.
        If you do no specify a controller, all controllers will be created.
        For example:

          rails generate devise:controllers users -c=sessions

        This will create a controller class at app/controllers/users/sessions_controller.rb like this:

          class Users::ConfirmationsController < Devise::ConfirmationsController
            content...
          end
      DESC

      source_root File.expand_path("../../templates/controllers", __FILE__)
      argument :scope, required: true,
        desc: "The scope to create controllers in, e.g. users, admins"
      class_option :controllers, aliases: "-c", type: :array,
        desc: "Select specific controllers to generate (#{CONTROLLERS.join(', ')})"

      def create_controllers
        @scope_prefix = scope.blank? ? '' : (scope.camelize + '::')
        controllers = options[:controllers] || CONTROLLERS
        controllers.each do |name|
          template "#{name}_controller.rb",
                   "app/controllers/#{scope}/#{name}_controller.rb"
        end
      end

      def show_readme
        readme "README" if behavior == :invoke
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 5 rubygems

Version Path
devise-4.3.0 lib/generators/devise/controllers_generator.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/devise-4.2.1/lib/generators/devise/controllers_generator.rb
devise-4.2.1 lib/generators/devise/controllers_generator.rb
devise-4.2.0 lib/generators/devise/controllers_generator.rb
devise-3.5.10 lib/generators/devise/controllers_generator.rb
devise-4.0.3 lib/generators/devise/controllers_generator.rb
devise-4.1.1 lib/generators/devise/controllers_generator.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/devise-4.1.0/lib/generators/devise/controllers_generator.rb
devise-4.1.0 lib/generators/devise/controllers_generator.rb
devise-3.5.9 lib/generators/devise/controllers_generator.rb
devise-4.0.2 lib/generators/devise/controllers_generator.rb
devise-4.0.1 lib/generators/devise/controllers_generator.rb
devise-3.5.8 lib/generators/devise/controllers_generator.rb
devise-3.5.7 lib/generators/devise/controllers_generator.rb
devise-4.0.0 lib/generators/devise/controllers_generator.rb
devise-4.0.0.rc2 lib/generators/devise/controllers_generator.rb
devise-4.0.0.rc1 lib/generators/devise/controllers_generator.rb
devise-3.5.6 lib/generators/devise/controllers_generator.rb
devise-3.5.5 lib/generators/devise/controllers_generator.rb
devise-3.5.4 lib/generators/devise/controllers_generator.rb