Class: Teleport::DeviseGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/teleport/devise.rb

Instance Method Summary collapse

Instance Method Details

#addObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/generators/teleport/devise.rb', line 5

def add
  gem 'devise'
  gem 'cancancan'

  gem_group :development do
    gem 'letter_opener'
  end

  Bundler.with_clean_env do
    run "bundle install"
  end

  generate 'cancan:ability'
  generate 'devise:install'
  generate 'devise:views'

  insert_into_file "config/environments/development.rb", before: "end\n" do
%Q{
  config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }
  config.action_mailer.delivery_method = :letter_opener

}
  end

  insert_into_file 'app/controllers/application_controller.rb', after: "protect_from_forgery with: :exception\n" do
%Q{
  before_action :authenticate_user!

  rescue_from CanCan::AccessDenied do |exception|
redirect_to root_url, alert: exception.message
  end

}
  end

  copy_file 'devise/devise.ru.yml', 'config/locales/devise.ru.yml'

  model = ask "Type MODEL to bootstrap devise:"
  generate "devise #{model}"

  with_oauth = ask 'Add oauth? (y/n)'
  generate 'devise_oauth' if with_oauth =~ /y/
end