Class: Kowl::ControllerGenerator

Inherits:
Generators::Base show all
Defined in:
lib/kowl/generators/controller_generator.rb

Instance Method Summary collapse

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_authObject

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 options[:noauth]
    app_str = "      protect_from_forgery with: :exception\n      include ErrorHandlers     # Application fallbacks\n      helper :all\n    APP\n    inject_into_file 'app/controllers/application_controller.rb', optimize_indentation(app_str, 2), after: \"class ApplicationController < ActionController::Base\\n\"\n    copy_file('concerns/noauth/error_handlers.rb', 'app/controllers/concerns/error_handlers.rb')\n  else\n    app_str = <<~APP\n      protect_from_forgery with: :exception\n      before_action :authenticate_user!\n      impersonates :user\n\n      include Authentication    # Devise/Authentication stuff\n      include Authorization     # To determine if a user is authorized to do a specific action\n      include ErrorHandlers     # Application fallbacks\n      helper :all\n    APP\n\n    inject_into_file 'app/controllers/application_controller.rb', optimize_indentation(app_str, 2), after: \"class ApplicationController < ActionController::Base\\n\"\n    directory 'concerns/auth', 'app/controllers/concerns', force: true\n  end\nend\n"

#enable_additional_flash_typesObject

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_immuatableObject



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_optionsObject

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 set_default_url_options
  mailer_str = "    before_action :mailer_set_url_options unless Rails.env.production?\n\n    private\n\n    def mailer_set_url_options\n      ActionMailer::Base.default_url_options[:host] = request.host_with_port\n    end\n  MAILER_STR\n  inject_into_file 'app/controllers/application_controller.rb', optimize_indentation(mailer_str, 2), after: \"helper :all\\n\"\nend\n"