Class: Godmin::AuthenticationGenerator

Inherits:
Generators::Base
  • Object
show all
Defined in:
lib/generators/godmin/authentication/authentication_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_modelObject



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

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

#create_routeObject



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

def create_route
  inject_into_file "config/routes.rb", after: "godmin do\n" do
    "      resource :session, only: [:new, :create, :destroy]\n    END\n  end\nend\n".strip_heredoc.indent(4)

#create_sessions_controllerObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/godmin/authentication/authentication_generator.rb', line 30

def create_sessions_controller
  create_file ["app/controllers", namespace, "sessions_controller.rb"].compact.join("/") do
    if namespace
      "        module \#{namespace.camelize}\n          class SessionsController < ApplicationController\n            include Godmin::Authentication::Sessions\n          end\n        end\n      END\n    else\n      <<-END.strip_heredoc\n        class SessionsController < ApplicationController\n          include Godmin::Authentication::Sessions\n        end\n      END\n    end\n  end\nend\n".strip_heredoc

#modify_application_controllerObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/generators/godmin/authentication/authentication_generator.rb', line 50

def modify_application_controller
  inject_into_file ["app/controllers", namespace, "application_controller.rb"].compact.join("/"), after: "Godmin::Application\n" do
    "      include Godmin::Authentication\n\n      def admin_user_class\n        \#{[namespace, @model.underscore].compact.join(\"/\").camelize}\n      end\n    END\n  end\nend\n".strip_heredoc.indent(namespace.nil? ? 2 : 4)

#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 ["app/models", namespace, "#{@model.underscore}.rb"].compact.join("/"), after: "ActiveRecord::Base\n" do
    "      include Godmin::Authentication::User\n\n      def self.login_column\n        :email\n      end\n    END\n  end\nend\n".strip_heredoc.indent(namespace.nil? ? 2 : 4)