Class: Seivan::Generators::AuthenticationGenerator

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

Instance Method Summary collapse

Methods inherited from Base

banner, source_root

Instance Method Details

#add_gemsObject



14
15
16
17
# File 'lib/generators/seivan/authentication/authentication_generator.rb', line 14

def add_gems
  gem "bcrypt-ruby", :require => "bcrypt" unless File.read(destination_path("Gemfile")).include? "bcrypt"
  gem "mocha", :group => :test unless File.read(destination_path("Gemfile")).include? "mocha"
end

#create_controller_filesObject



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

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



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

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



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

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

#create_migrationObject



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

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

#create_model_filesObject



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

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

#create_routesObject



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

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_#{user_singular_name}"
end

#create_test_filesObject



55
56
57
58
59
60
# File 'lib/generators/seivan/authentication/authentication_generator.rb', line 55

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

#load_and_include_authenticationObject



50
51
52
53
# File 'lib/generators/seivan/authentication/authentication_generator.rb', line 50

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