diff --git a/Gemfile.lock b/Gemfile.lock index d68dd0ae3c6..151cba7ed82 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -38,6 +38,7 @@ PATH activesupport (= 7.1.0.alpha) nio4r (~> 2.0) websocket-driver (>= 0.6.1) + zeitwerk (~> 2.5) actionmailbox (7.1.0.alpha) actionpack (= 7.1.0.alpha) activejob (= 7.1.0.alpha) diff --git a/actioncable/actioncable.gemspec b/actioncable/actioncable.gemspec index 889cf30ea6e..d39f80e22a5 100644 --- a/actioncable/actioncable.gemspec +++ b/actioncable/actioncable.gemspec @@ -37,4 +37,5 @@ Gem::Specification.new do |s| s.add_dependency "nio4r", "~> 2.0" s.add_dependency "websocket-driver", ">= 0.6.1" + s.add_dependency "zeitwerk", "~> 2.5" end diff --git a/actioncable/lib/action_cable.rb b/actioncable/lib/action_cable.rb index 3827584b518..5fecfe8ab14 100644 --- a/actioncable/lib/action_cable.rb +++ b/actioncable/lib/action_cable.rb @@ -27,9 +27,22 @@ require "active_support" require "active_support/rails" require "action_cable/version" -module ActionCable - extend ActiveSupport::Autoload +require "zeitwerk" +Zeitwerk::Loader.for_gem.tap do |loader| + loader.inflector.inflect("postgresql" => "PostgreSQL") + # You only want to load the adapters that are needed at runtime. + loader.do_not_eager_load("#{__dir__}/action_cable/subscription_adapter") + + # This directory contains generators, templates, documentation, etc. + # Generators are required on demand, so we can just ignore it all. + loader.ignore("#{__dir__}/rails") + loader.ignore("#{__dir__}/action_cable/gem_version.rb") + + loader.setup +end + +module ActionCable INTERNAL = { message_types: { welcome: "welcome", @@ -51,12 +64,4 @@ module ActionCable module_function def server @server ||= ActionCable::Server::Base.new end - - autoload :Server - autoload :Connection - autoload :Channel - autoload :RemoteConnections - autoload :SubscriptionAdapter - autoload :TestHelper - autoload :TestCase end diff --git a/actioncable/lib/action_cable/channel.rb b/actioncable/lib/action_cable/channel.rb deleted file mode 100644 index d5118b9dc9d..00000000000 --- a/actioncable/lib/action_cable/channel.rb +++ /dev/null @@ -1,17 +0,0 @@ -# frozen_string_literal: true - -module ActionCable - module Channel - extend ActiveSupport::Autoload - - eager_autoload do - autoload :Base - autoload :Broadcasting - autoload :Callbacks - autoload :Naming - autoload :PeriodicTimers - autoload :Streams - autoload :TestCase - end - end -end diff --git a/actioncable/lib/action_cable/connection.rb b/actioncable/lib/action_cable/connection.rb deleted file mode 100644 index 20b5dbe78d9..00000000000 --- a/actioncable/lib/action_cable/connection.rb +++ /dev/null @@ -1,22 +0,0 @@ -# frozen_string_literal: true - -module ActionCable - module Connection - extend ActiveSupport::Autoload - - eager_autoload do - autoload :Authorization - autoload :Base - autoload :ClientSocket - autoload :Identification - autoload :InternalChannel - autoload :MessageBuffer - autoload :Stream - autoload :StreamEventLoop - autoload :Subscriptions - autoload :TaggedLoggerProxy - autoload :TestCase - autoload :WebSocket - end - end -end diff --git a/actioncable/lib/action_cable/engine.rb b/actioncable/lib/action_cable/engine.rb index e369068ade8..4d6ae04ad27 100644 --- a/actioncable/lib/action_cable/engine.rb +++ b/actioncable/lib/action_cable/engine.rb @@ -2,7 +2,6 @@ require "rails" require "action_cable" -require "action_cable/helpers/action_cable_helper" require "active_support/core_ext/hash/indifferent_access" module ActionCable @@ -11,8 +10,6 @@ module ActionCable config.action_cable.mount_path = ActionCable::INTERNAL[:default_mount_path] config.action_cable.precompile_assets = true - config.eager_load_namespaces << ActionCable - initializer "action_cable.helpers" do ActiveSupport.on_load(:action_view) do include ActionCable::Helpers::ActionCableHelper diff --git a/actioncable/lib/action_cable/server.rb b/actioncable/lib/action_cable/server.rb deleted file mode 100644 index 76d3d962ffa..00000000000 --- a/actioncable/lib/action_cable/server.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -module ActionCable - module Server - extend ActiveSupport::Autoload - - eager_autoload do - autoload :Base - autoload :Broadcasting - autoload :Connections - autoload :Configuration - - autoload :Worker - end - end -end diff --git a/actioncable/lib/action_cable/server/worker.rb b/actioncable/lib/action_cable/server/worker.rb index e1b75d4a69f..686598f4b4a 100644 --- a/actioncable/lib/action_cable/server/worker.rb +++ b/actioncable/lib/action_cable/server/worker.rb @@ -2,7 +2,6 @@ require "active_support/callbacks" require "active_support/core_ext/module/attribute_accessors_per_thread" -require "action_cable/server/worker/active_record_connection_management" require "concurrent" module ActionCable diff --git a/actioncable/lib/action_cable/subscription_adapter.rb b/actioncable/lib/action_cable/subscription_adapter.rb deleted file mode 100644 index 6a9d5c20805..00000000000 --- a/actioncable/lib/action_cable/subscription_adapter.rb +++ /dev/null @@ -1,12 +0,0 @@ -# frozen_string_literal: true - -module ActionCable - module SubscriptionAdapter - extend ActiveSupport::Autoload - - autoload :Base - autoload :Test - autoload :SubscriberMap - autoload :ChannelPrefix - end -end diff --git a/actioncable/lib/action_cable/subscription_adapter/async.rb b/actioncable/lib/action_cable/subscription_adapter/async.rb index c9930299c7e..1647cbfc20a 100644 --- a/actioncable/lib/action_cable/subscription_adapter/async.rb +++ b/actioncable/lib/action_cable/subscription_adapter/async.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require "action_cable/subscription_adapter/inline" - module ActionCable module SubscriptionAdapter class Async < Inline # :nodoc: diff --git a/actioncable/lib/action_cable/subscription_adapter/test.rb b/actioncable/lib/action_cable/subscription_adapter/test.rb index 83c28f41a19..ecfeee405a8 100644 --- a/actioncable/lib/action_cable/subscription_adapter/test.rb +++ b/actioncable/lib/action_cable/subscription_adapter/test.rb @@ -1,7 +1,5 @@ # frozen_string_literal: true -require_relative "async" - module ActionCable module SubscriptionAdapter # == Test adapter for Action Cable diff --git a/actioncable/test/channel/stream_test.rb b/actioncable/test/channel/stream_test.rb index 7d04ceb436f..6b520695e5f 100644 --- a/actioncable/test/channel/stream_test.rb +++ b/actioncable/test/channel/stream_test.rb @@ -288,8 +288,6 @@ module ActionCable::StreamTests end end - require "action_cable/subscription_adapter/async" - class UserCallbackChannel < ActionCable::Channel::Base def subscribed stream_from :channel do diff --git a/actioncable/test/subscription_adapter/redis_test.rb b/actioncable/test/subscription_adapter/redis_test.rb index c001b352cee..b078e6bb019 100644 --- a/actioncable/test/subscription_adapter/redis_test.rb +++ b/actioncable/test/subscription_adapter/redis_test.rb @@ -4,8 +4,6 @@ require "test_helper" require_relative "common" require_relative "channel_prefix" -require "action_cable/subscription_adapter/redis" - class RedisAdapterTest < ActionCable::TestCase include CommonSubscriptionAdapterTest include ChannelPrefixTest