Class: Godmin::AuthenticationGenerator

Inherits:
Generators::NamedBase show all
Defined in:
lib/generators/godmin/authentication/authentication_generator.rb

Instance Method Summary collapse

Methods inherited from Generators::Base

source_paths

Instance Method Details

#create_modelObject



6
7
8
# File 'lib/generators/godmin/authentication/authentication_generator.rb', line 6

def create_model
  generate "model", "#{name} email:string password_digest:text --no-test-framework"
end

#create_routeObject



22
23
24
# File 'lib/generators/godmin/authentication/authentication_generator.rb', line 22

def create_route
  route "resource :session, only: [:new, :create, :destroy]"
end

#create_sessions_controllerObject



26
27
28
# File 'lib/generators/godmin/authentication/authentication_generator.rb', line 26

def create_sessions_controller
  template "sessions_controller.rb", File.join("app/controllers", namespaced_path, "sessions_controller.rb")
end

#modify_application_controllerObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/generators/godmin/authentication/authentication_generator.rb', line 30

def modify_application_controller
  inject_into_file File.join("app/controllers", namespaced_path, "application_controller.rb"), after: "Godmin::ApplicationController\n" do
    <<-END.strip_heredoc.indent(namespace ? 4 : 2)
      include Godmin::Authentication

      def admin_user_class
        #{class_name}
      end
    END
  end
end

#modify_modelObject



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/generators/godmin/authentication/authentication_generator.rb', line 10

def modify_model
  inject_into_file File.join("app/models", class_path, "#{file_name}.rb"), after: "ActiveRecord::Base\n" do
    <<-END.strip_heredoc.indent(namespace ? 4 : 2)
      include Godmin::Authentication::User

      def self.login_column
        :email
      end
    END
  end
end