Class: Hello::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Hello::InstallGenerator
- Defined in:
- lib/generators/hello/install/install_generator.rb
Instance Method Summary collapse
- #append_to_the_routes ⇒ Object
- #copy_the_initializer ⇒ Object
- #create_layout_file ⇒ Object
- #create_models ⇒ Object
- #create_the_migrations ⇒ Object
- #generate_helper ⇒ Object
- #generate_onboarding ⇒ Object
-
#generate_root ⇒ Object
a root route is needed we were previously redirecting to /hello which caused a redirection loop bug.
- #locale_fix ⇒ Object
Instance Method Details
#append_to_the_routes ⇒ Object
29 30 31 32 |
# File 'lib/generators/hello/install/install_generator.rb', line 29 def append_to_the_routes route 'mount Hello::Engine => "/hello"' route "get '/hello/sign_out' => 'hello/authentication/sessions#sign_out'" end |
#copy_the_initializer ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/generators/hello/install/install_generator.rb', line 4 def copy_the_initializer copy_file 'initializer.rb', 'config/initializers/hello.rb' append_file 'config/initializers/session_store.rb', " # Suggestion added by gem 'hello-rails' Rails.application.config.session_options[:expire_after] = 10.years " end |
#create_layout_file ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/generators/hello/install/install_generator.rb', line 38 def create_layout_file destination = 'app/views/layouts/application.html.erb' answer = ask('Replace application.html.erb automatically? [Yn]') answer_yes = answer.blank? || answer.downcase.starts_with?('y') if answer_yes copy_file 'application.html.erb', 'app/views/layouts/application.html.erb' else the_template_path = File.('../templates', __FILE__) app_erb_path = File.join(the_template_path, 'application.html.erb') content = open(app_erb_path).read puts ('-' * 100).light_yellow puts ' We recommend you add these elements to your application.html.erb file'.light_yellow puts ('-' * 100).light_yellow puts content.light_green.on_black.bold puts ('-' * 100).light_yellow end end |
#create_models ⇒ Object
58 59 60 |
# File 'lib/generators/hello/install/install_generator.rb', line 58 def create_models directory 'models', 'app/models' end |
#create_the_migrations ⇒ Object
34 35 36 |
# File 'lib/generators/hello/install/install_generator.rb', line 34 def create_the_migrations rake 'hello:install:migrations' end |
#generate_helper ⇒ Object
17 18 19 |
# File 'lib/generators/hello/install/install_generator.rb', line 17 def generate_helper copy_file 'hello_helper.rb', 'app/helpers/hello_helper.rb' end |
#generate_onboarding ⇒ Object
62 63 64 65 66 67 68 69 |
# File 'lib/generators/hello/install/install_generator.rb', line 62 def generate_onboarding route %( get 'onboarding' => 'onboarding#index' post 'onboarding' => 'onboarding#continue' ) copy_file 'onboarding/onboarding_controller.rb', 'app/controllers/onboarding_controller.rb' copy_file 'onboarding/index.html.erb', 'app/views/onboarding/index.html.erb' end |
#generate_root ⇒ Object
a root route is needed we were previously redirecting to /hello which caused a redirection loop bug
23 24 25 26 27 |
# File 'lib/generators/hello/install/install_generator.rb', line 23 def generate_root route "root to: 'root#index'" copy_file 'root/root_controller.rb', 'app/controllers/root_controller.rb' copy_file 'root/index.html.erb', 'app/views/root/index.html.erb' end |
#locale_fix ⇒ Object
12 13 14 15 |
# File 'lib/generators/hello/install/install_generator.rb', line 12 def locale_fix gsub_file 'config/locales/en.yml', 'hello: "Hello world"', 'hello_world: "Hello world"' rescue Errno::ENOENT end |