Class: Nifty::Generators::AuthenticationGenerator

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

Instance Method Summary collapse

Methods inherited from Base

banner, source_root

Instance Method Details

#add_gemsObject



19
20
21
22
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 19

def add_gems
  add_gem "bcrypt-ruby", :require => "bcrypt"
  add_gem "mocha", :group => :test
end

#create_controller_filesObject



29
30
31
32
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 29

def create_controller_files
  template 'users_controller.rb', "app/controllers/#{user_plural_name}_controller.rb"
  template 'sessions_controller.rb', "app/controllers/#{session_plural_name}_controller.rb"
end

#create_helper_filesObject



34
35
36
37
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 34

def create_helper_files
  template 'users_helper.rb', "app/helpers/#{user_plural_name}_helper.rb"
  template 'sessions_helper.rb', "app/helpers/#{session_plural_name}_helper.rb"
end

#create_lib_filesObject



46
47
48
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 46

def create_lib_files
  template 'controller_authentication.rb', 'lib/controller_authentication.rb'
end

#create_migrationObject



59
60
61
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 59

def create_migration
  migration_template 'migration.rb', "db/migrate/create_#{user_plural_name}.rb"
end

#create_model_filesObject



24
25
26
27
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 24

def create_model_files
  template 'user.rb', "app/models/#{user_singular_name}.rb"
  template 'authlogic_session.rb', "app/models/#{user_singular_name}_session.rb" if options.authlogic?
end

#create_routesObject



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

def create_routes
  route "resources #{user_plural_name.to_sym.inspect}"
  route "resources #{session_plural_name.to_sym.inspect}"
  route "match 'login' => '#{session_plural_name}#new', :as => :login"
  route "match 'logout' => '#{session_plural_name}#destroy', :as => :logout"
  route "match 'signup' => '#{user_plural_name}#new', :as => :signup"
  route "match '#{user_singular_name}/edit' => '#{user_plural_name}#edit', :as => :edit_current_#{user_singular_name}"
end

#create_test_filesObject



68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 68

def create_test_files
  if test_framework == :rspec
    template 'fixtures.yml', "spec/fixtures/#{user_plural_name}.yml"
    template 'tests/rspec/user.rb', "spec/models/#{user_singular_name}_spec.rb"
    template 'tests/rspec/users_controller.rb', "spec/controllers/#{user_plural_name}_controller_spec.rb"
    template 'tests/rspec/sessions_controller.rb', "spec/controllers/#{session_plural_name}_controller_spec.rb"
  else
    template 'fixtures.yml', "test/fixtures/#{user_plural_name}.yml"
    template "tests/#{test_framework}/user.rb", "test/unit/#{user_singular_name}_test.rb"
    template "tests/#{test_framework}/users_controller.rb", "test/functional/#{user_plural_name}_controller_test.rb"
    template "tests/#{test_framework}/sessions_controller.rb", "test/functional/#{session_plural_name}_controller_test.rb"
  end
end

#create_view_filesObject



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

def create_view_files
  template "views/#{view_language}/signup.html.#{view_language}", "app/views/#{user_plural_name}/new.html.#{view_language}"
  template "views/#{view_language}/edit.html.#{view_language}", "app/views/#{user_plural_name}/edit.html.#{view_language}"
  template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{user_plural_name}/_form.html.#{view_language}"
  template "views/#{view_language}/login.html.#{view_language}", "app/views/#{session_plural_name}/new.html.#{view_language}"
end

#load_and_include_authenticationObject



63
64
65
66
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 63

def load_and_include_authentication
  inject_into_class "config/application.rb", "Application", "    config.autoload_paths << \"\#{config.root}/lib\""
  inject_into_class "app/controllers/application_controller.rb", "ApplicationController", "  include ControllerAuthentication\n"
end