require "rails" require "active_record/railtie" require "action_view/railtie" module ::RailsConnector class Engine < Rails::Engine config.to_prepare { RailsConnector::Configuration.to_prepare } config.after_initialize { RailsConnector::Configuration.after_initialize } # make sure our exceptions cause an adequate error page and http status code config.action_dispatch.rescue_responses["RailsConnector::ResourceNotFound"] = :not_found initializer "Rails patches" do config.to_prepare do ActiveSupport.on_load(:active_record) do include RailsConnector::CoreExtensions::ActiveRecord::Core end end end initializer "rails_connector.add_fiona_time_type" do ActiveSupport.on_load(:active_record) do ActiveRecord::Type.register(:fiona_datetime, FionaDateTime) end end initializer "rails_connector.add_cms_routing_paths", after: :add_routing_paths do |app| cms_route = File.expand_path("cms_routes.rb", paths["config"].to_a.first) app.routes_reloader.paths.push(cms_route) end initializer "rails_connector.add_assets" do |app| app.config.assets.precompile += %w( editmarker.css editmarker.js ) end # Expose rails connector runtime to controller for logging. initializer "rails_connector.log_runtime" do |_app| runtime = begin RailsConnector::ControllerRuntime rescue NameError nil end if runtime RailsConnector::LogSubscriber.attach_to :rails_connector ActiveSupport.on_load(:action_controller_base) do include runtime end end end initializer "rails_connector.configure_database", before: :load_config_initializers do |_app| RailsConnector::Configuration.configure_cms_database end initializer "rails_connector.routing_helpers" do ActionDispatch::TestRequest.include RailsConnector::CmsTestRequest if Rails.env == "test" config.to_prepare do ActiveSupport.on_load(:action_controller_base) do include CmsRoutingHelper end end ActiveSupport.on_load(:action_view_base) do include CmsRoutingHelper end end initializer "zeitwerk.autoloader" do if Rails::VERSION::MAJOR >= 6 && Rails.autoloaders.zeitwerk_enabled? Rails.autoloaders.main.inflector.inflect("ses" => "SES") Rails.autoloaders.each do |autoloader| autoloader.ignore("#{config.root}/lib/generators") autoloader.ignore("#{config.root}/lib/meta_eager_loader.rb") autoloader.ignore("#{config.root}/lib/version.rb") autoloader.ignore("#{config.root}/lib/rails_connector/core_extensions.rb") autoloader.ignore("#{config.root}/lib/rails_connector/core_extensions/time.rb") autoloader.ignore("#{config.root}/lib/rails_connector/core_extensions/active_record/core.rb") autoloader.ignore("#{config.root}/lib/rails_connector/errors.rb") autoloader.ignore("#{config.root}/lib/rails_connector/fiona_date_time.rb") autoloader.ignore("#{config.root}/lib/rails_connector/rack_middlewares.rb") end end end config.autoload_paths += paths["lib"].to_a config.autoload_once_paths += paths["lib/rails_connector"].to_a config.eager_load_paths += paths["lib/rails_connector"].to_a initializer "middleware.config" do RailsConnector.rack_middlewares.each { |middleware| config.app_middleware.use middleware } end end end