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
    <<-END.strip_heredoc.indent(4)
      resource :session, only: [:new, :create, :destroy]
    END
  end
end

#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
      <<-END.strip_heredoc
        module #{namespace.camelize}
          class SessionsController < ApplicationController
            include Godmin::Authentication::Sessions
          end
        end
      END
    else
      <<-END.strip_heredoc
        class SessionsController < ApplicationController
          include Godmin::Authentication::Sessions
        end
      END
    end
  end
end

#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
    <<-END.strip_heredoc.indent(namespace.nil? ? 2 : 4)
      include Godmin::Authentication

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

      def self.login_column
        :email
      end
    END
  end
end