Class: I0n::Generators::AuthenticationGenerator

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

Instance Method Summary collapse

Instance Method Details

#create_authentication_lib_and_include_in_application_helperObject



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

def create_authentication_lib_and_include_in_application_helper
  copy_file "lib/authentication.rb", "#{Rails.root}/lib/authentication.rb" 
  inject_into_class("app/controllers/application_controller.rb", ApplicationController, "include Authentication\n")
end

#create_controllersObject



40
41
42
43
44
45
# File 'lib/generators/i0n/authentication/authentication_generator.rb', line 40

def create_controllers
  generate("controller", "user_sessions")   
  generate("controller", "users")
  inject_into_class("app/controllers/users_controller.rb", UsersController, IO.read("#{AuthenticationGenerator.source_root}/app/controllers/_users_controller.rb")) 
  inject_into_class("app/controllers/user_sessions_controller.rb", UserSessionsController, IO.read("#{AuthenticationGenerator.source_root}/app/controllers/_user_sessions_controller.rb"))
end

#create_modelsObject



35
36
37
38
# File 'lib/generators/i0n/authentication/authentication_generator.rb', line 35

def create_models
  generate("model", "user email:string password_hash:string password_salt:string")
  insert_into_file("app/models/user.rb", IO.read("#{AuthenticationGenerator.source_root}/app/models/_user.rb"), :before => "end" ) 
end

#create_rake_tasksObject



52
53
54
# File 'lib/generators/i0n/authentication/authentication_generator.rb', line 52

def create_rake_tasks
  copy_file "lib/tasks/create_default_user.rake", "#{Rails.root}/lib/tasks/create_default_user.rake" 
end

#create_routesObject



27
28
29
30
31
32
33
# File 'lib/generators/i0n/authentication/authentication_generator.rb', line 27

def create_routes
  route("match 'register' => 'users#new', :as => :register")
  route("resources :users")    
  route("resources :user_sessions, :only => [:new, :create, :destroy]")
  route("match 'login' => 'user_sessions#new', :as => :login")
  route("match 'logout' => 'user_sessions#destroy', :as => :logout")
end

#create_viewsObject



47
48
49
50
# File 'lib/generators/i0n/authentication/authentication_generator.rb', line 47

def create_views
  directory "app/views/users", "#{Rails.root}/app/views/users"
  directory "app/views/user_sessions", "#{Rails.root}/app/views/user_sessions" 
end

#gemfileObject



7
8
9
# File 'lib/generators/i0n/authentication/authentication_generator.rb', line 7

def gemfile
  gem("bcrypt-ruby", :require => 'bcrypt')  
end

#setup_applicationObject



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

def setup_application
  application do
    '
    # Configure sensitive parameters which will be filtered from the log file.
    config.filter_parameters += [:password, :password_confirmation]

    config.autoload_paths += %W(#{Rails.root}/lib)
    '
  end  
end