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

#create_controller_filesObject



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

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_include_lineObject



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

def create_include_line
  inject_into_class 'app/controllers/application_controller.rb', 'ApplicationController', '  include Authentication'
end

#create_lib_filesObject



43
44
45
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 43

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

#create_migrationObject



55
56
57
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 55

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

#create_model_filesObject



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

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



47
48
49
50
51
52
53
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 47

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"
end

#create_test_filesObject



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/generators/nifty/authentication/authentication_generator.rb', line 63

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



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

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}/login.html.#{view_language}", "app/views/#{session_plural_name}/new.html.#{view_language}"
end

#crete_helper_filesObject



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

def crete_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