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
48
|
# File 'lib/generators/happy_seed/omniauth/omniauth_generator.rb', line 13
def install_omniauth
return if already_installed
require_generator DeviseGenerator
migration_template("make_email_nullable.rb", "db/migrate/make_email_nullable.rb" )
gem 'omniauth'
gem 'omniauth-oauth2', '1.3.1'
Bundler.with_clean_env do
run "bundle install --without production"
end
generate 'model identity user:references provider:string accesstoken:string uid:string name:string email:string nickname:string image:string phone:string urls:string'
remove_file 'app/models/identity.rb'
remove_file 'spec/models/identity_spec.rb'
directory 'app'
directory 'spec'
begin
gsub_file "app/models/user.rb", "devise :", "devise :omniauthable, :"
gsub_file "app/models/user.rb", ", :validatable", ""
inject_into_class "app/models/user.rb", "User", " has_many :identities, dependent: :destroy\n"
inject_into_class "app/models/user.rb", "User", File.read( find_in_source_paths( "user.rb" ) )
rescue
say_status :user_model, "Unable to add omniauthable to app/models/users.rb", :red
end
gsub_file 'config/routes.rb', "devise_for :users, :controllers => {", "devise_for :users, :controllers => { omniauth_callbacks: 'omniauth_callbacks', registrations: 'registrations', "
directory "docs"
end
|