Class: HappySeed::Generators::OmniauthGenerator

Inherits:
HappySeedGenerator
  • Object
show all
Includes:
Rails::Generators::Migration
Defined in:
lib/generators/happy_seed/omniauth/omniauth_generator.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.fingerprintObject



9
10
11
# File 'lib/generators/happy_seed/omniauth/omniauth_generator.rb', line 9

def self.fingerprint
  gem_available?( 'omniauth' )
end

Instance Method Details

#install_omniauthObject



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'
  # route "match '/profile/:id/finish_signup' => 'users#finish_signup', via: [:get, :patch], :as => :finish_signup"
  # route "get '/account' => 'users#show', as: 'user'"

  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"
    # insert_into_file "app/models/user.rb", File.read( find_in_source_paths( "user.rb" ) ), :before => "\nend\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