Class: Zoo::Generators::AuthenticationGenerator

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

Instance Method Summary collapse

Methods inherited from Base

banner, source_root

Instance Method Details

#add_gemsObject



16
17
18
19
20
# File 'lib/generators/zoo/authentication/authentication_generator.rb', line 16

def add_gems                        
  add_gem "haml-rails"
  add_gem "bcrypt-ruby", require: "bcrypt"
  add_gem "mocha", group: :test  
end

#create_controller_filesObject



26
27
28
29
# File 'lib/generators/zoo/authentication/authentication_generator.rb', line 26

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



31
32
33
34
# File 'lib/generators/zoo/authentication/authentication_generator.rb', line 31

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



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

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

#create_migrationObject



56
57
58
# File 'lib/generators/zoo/authentication/authentication_generator.rb', line 56

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

#create_model_filesObject



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

def create_model_files
  template 'user.rb', "app/models/#{user_singular_name}.rb"
end

#create_routesObject



47
48
49
50
51
52
53
54
# File 'lib/generators/zoo/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"
  route "match '#{user_singular_name}/edit' => '#{user_plural_name}#edit', as : :edit_current_#{user_singular_name}"
end

#create_test_filesObject



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

def create_test_files
  if test_framework == :rspec
    template 'factory.rb', "spec/factories/#{user_plural_name}.rb"  
    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 'factory.rb', "test/factories/#{user_plural_name}.rb"          
    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



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

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



60
61
62
63
# File 'lib/generators/zoo/authentication/authentication_generator.rb', line 60

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