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
    "include Godmin::Authentication\n\ndef admin_user_class\n\#{full_class_name}\nend\n".strip_heredoc.indent(namespace ? 4 : 2)
  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
    "include Godmin::Authentication::User\n\ndef self.login_column\n:email\nend\n".strip_heredoc.indent(namespace ? 4 : 2)
  end
end