Class: DailycredGenerator

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

Constant Summary collapse

CLIENT_ID_DEFAULT =
'YOUR_CLIENT_ID'
CLIENT_SECRET_DEFAULT =
'YOUR_SECRET_KEY'
APP_ROUTES_LINES =
<<-EOS
mount Dailycred::Engine => '/auth', :as => 'dailycred_engine'
EOS
APP_CONTROLLER_LINES =
<<-EOS
helper_method :current_user

private

# helper method for getting the current signed in user
def current_user
  begin
    @current_user || User.find(session[:user_id]) if session[:user_id]
  rescue
    nil
  end
end
EOS

Instance Method Summary collapse

Instance Method Details

#installObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/generators/dailycred_generator.rb', line 38

def install
  puts "DEPRECATED: calling `rails generate dailycred` has been deprecated. Please use `rails generate dailycred:install`."
  # copy initializer
  template "omniauth.rb", "config/initializers/omniauth.rb"
  # get client info from login if they didnt specify info
  puts "Please manually configure your API keys in config/initializers/omniauth.rb"
  if options.bootstrap?
    # application controller
    insert_into_file "app/controllers/application_controller.rb", APP_CONTROLLER_LINES, :after => /class ApplicationController\n|class ApplicationController .*\n/
    # user model
    copy_file "user.rb", "app/models/user.rb"
    # user migration
    copy_file "migration_create_user.rb", "db/migrate/#{Time.now.strftime('%Y%m%d%H%M%S')}_create_users.rb"
    # confiffg/routes
    inject_into_file "config/routes.rb", APP_ROUTES_LINES, :after => ".draw do\n"
  else
    puts "Make sure you implement your omniauth callback. For directions visit https://github.com/intridea/omniauth#integrating-omniauth-into-your-application"
  end
end