Class: Kowl::ControllerGenerator
- Inherits:
-
Generators::Base
- Object
- Rails::Generators::Base
- Generators::Base
- Kowl::ControllerGenerator
- Defined in:
- lib/kowl/generators/controller_generator.rb
Instance Method Summary collapse
-
#app_controller_auth ⇒ Object
Add application_controller callbacks depending on if the application requires user auth or not.
-
#enable_additional_flash_types ⇒ Object
Enable additional flash_types to the application_controller.
- #make_controller_immuatable ⇒ Object
-
#set_default_url_options ⇒ Object
This allows the application to dynamically assign the mail delivery host when running in development and staging.
Methods inherited from Generators::Base
default_source_root, source_paths
Methods included from Docker
#alpine_docker_dependencies, #app_js_volumes, #app_volumes, #db_volumes, #debian_database_dependencies, #debian_docker_dependencies, #docker_app_command, #docker_compose_database_string, #docker_databases, #docker_depends_on, #docker_port_watcher, #docker_redis_service, #docker_sidekiq_service, #docker_variables, #docker_volumes, #docker_webpacker_service, #dockerfile_database_args, #dockerfile_migration_snip, #js_volumes, #mysql_volumes, #postgresql_volumes, #redis_volumes
Methods included from Actions
#add_extension_routes, #add_package, #append_to_file, #database_route, #dev_config, #dup_file, #file_exists?, #mailer_gems, #mailer_route, #mk_dir, #move_file, #pry_gems, #rails_cmd, #remove_dir, #remove_file, #remove_gem, #replace_string_in_file, #robocop_test_engine, #sidekiq_route, #template_linter_gems
Instance Method Details
#app_controller_auth ⇒ Object
Add application_controller callbacks depending on if the application requires user auth or not
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 |
# File 'lib/kowl/generators/controller_generator.rb', line 13 def app_controller_auth if [:noauth] app_str = <<~APP protect_from_forgery with: :exception include ErrorHandlers # Application fallbacks helper :all APP inject_into_file 'app/controllers/application_controller.rb', optimize_indentation(app_str, 2), after: "class ApplicationController < ActionController::Base\n" copy_file('concerns/noauth/error_handlers.rb', 'app/controllers/concerns/error_handlers.rb') else app_str = <<~APP protect_from_forgery with: :exception before_action :authenticate_user! impersonates :user include Authentication # Devise/Authentication stuff include Authorization # To determine if a user is authorized to do a specific action include ErrorHandlers # Application fallbacks helper :all APP inject_into_file 'app/controllers/application_controller.rb', optimize_indentation(app_str, 2), after: "class ApplicationController < ActionController::Base\n" directory 'concerns/auth', 'app/controllers/concerns', force: true end end |
#enable_additional_flash_types ⇒ Object
Enable additional flash_types to the application_controller
58 59 60 61 62 |
# File 'lib/kowl/generators/controller_generator.rb', line 58 def enable_additional_flash_types flash_str = "add_flash_types :success, :error # Enable additional flash types across the application\n" inject_into_file 'app/controllers/application_controller.rb', optimize_indentation(flash_str, 2), after: "class ApplicationController < ActionController::Base\n" end |
#make_controller_immuatable ⇒ Object
39 40 41 |
# File 'lib/kowl/generators/controller_generator.rb', line 39 def make_controller_immuatable inject_into_file 'app/controllers/application_controller.rb', "# frozen_string_literal: true\n\n", before: "class ApplicationController < ActionController::Base\n" end |
#set_default_url_options ⇒ Object
This allows the application to dynamically assign the mail delivery host when running in development and staging
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/kowl/generators/controller_generator.rb', line 44 def mailer_str = <<~MAILER_STR before_action :mailer_set_url_options unless Rails.env.production? private def mailer_set_url_options ActionMailer::Base.default_url_options[:host] = request.host_with_port end MAILER_STR inject_into_file 'app/controllers/application_controller.rb', optimize_indentation(mailer_str, 2), after: "helper :all\n" end |