Class: Infinum::Omniauth::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Infinum::Omniauth::Generators::InstallGenerator
- Defined in:
- lib/generators/infinum/omniauth/install_generator.rb
Instance Method Summary collapse
-
#add_routes ⇒ Object
create_the_omniauth_controller.
-
#add_url_to_application ⇒ Object
ask_for_configuration.
- #ask_for_configuration ⇒ Object
-
#create_a_config_file ⇒ Object
add_url_to_application.
-
#create_the_omniauth_controller ⇒ Object
create_a_config_file.
-
#prompt_user ⇒ Object
add_routes.
Instance Method Details
#add_routes ⇒ Object
create_the_omniauth_controller
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/generators/infinum/omniauth/install_generator.rb', line 40 def add_routes routes = "\n"\ " get '/auth/:provider/callback', to: 'omniauth#success'\n"\ " get '/auth/failure' , to: 'omniauth#failure'\n"\ " get '/login/:provider', to: 'omniauth#login', as:\"login\"\n"\ " get '/logout', to: 'omniauth#logout', as:\"logout\"\n" append_to_file "config/routes.rb", routes, after: Regexp.new("^.*" + Regexp.escape("Application.routes.draw do") + ".*$", Regexp::IGNORECASE) end |
#add_url_to_application ⇒ Object
ask_for_configuration
18 19 20 21 22 |
# File 'lib/generators/infinum/omniauth/install_generator.rb', line 18 def add_url_to_application append_to_file "config/application.rb", "\n ENV['omniauth_infinum_url'] = \"http://accounts.infinum.co\#{Rails.env.development? ? '.dev' : ''}\"", after: Regexp.new("^.*" + Regexp.escape("class Application < Rails::Application") + ".*$", Regexp::IGNORECASE) end |
#ask_for_configuration ⇒ Object
12 13 14 15 16 |
# File 'lib/generators/infinum/omniauth/install_generator.rb', line 12 def ask_for_configuration @standalone = [:standalone] return nil if .no_config? @standalone = yes? "Use OmniAuth Infinum as a standalone method of authentification?" end |
#create_a_config_file ⇒ Object
add_url_to_application
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/generators/infinum/omniauth/install_generator.rb', line 24 def create_a_config_file if File.exists? "config/initializers/omniauth.rb" # An initializer exists, jus append to it append_to_file "config/initializers/omniauth.rb", "\n provider :infinum, INFINUM_APP_KEY, INFINUM_APP_SECRET\n", after: Regexp.new("^.*" + Regexp.escape("Rails.application.config.middleware.use OmniAuth::Builder do") + ".*$", Regexp::IGNORECASE) else # Create a new initializer copy_file "rails/config/initializers/omniauth.rb", "config/initializers/omniauth.rb" end end |
#create_the_omniauth_controller ⇒ Object
create_a_config_file
36 37 38 |
# File 'lib/generators/infinum/omniauth/install_generator.rb', line 36 def create_the_omniauth_controller copy_file "rails/app/controllers/omniauth_controller.rb", "app/controllers/omniauth_controller.rb" end |
#prompt_user ⇒ Object
add_routes
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/generators/infinum/omniauth/install_generator.rb', line 51 def prompt_user if @standalone system "rails g infinum:omniauth:auth --no_warnings;"\ "rails g infinum:omniauth:config;" say "Installation finished!", :green else say "Installation finished!", :green say "" say "To use this gem as a standalone authentification method run:" say " rails generate omniauth_infinum:auth" say "" say "To configure the authentification parameters run:" say " rails generate omniauth_infinum:config" end end |