mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactor Zeitwerk setup in Action Cable
I am trying to find a sweet spot here. Personally, not quite satisfied by having lib/action_cable/zeitwerk.rb. At the same time, trying to avoid too taking much space in lib/action_cable.rb. This patch also moves require_relative "action_cable/version" within ActionCable. Why? In a project, I like that the entrypoint defines the namespace. That is the main file for that namespace. Then, files below have it already created, and reopen it. I just find this deliberate order of execution to be natural, hierarchical, matching the project structure.
This commit is contained in:
parent
e17fe9eb6e
commit
645239817d
2 changed files with 17 additions and 34 deletions
|
@ -25,11 +25,26 @@
|
|||
|
||||
require "active_support"
|
||||
require "active_support/rails"
|
||||
require "zeitwerk"
|
||||
|
||||
require_relative "action_cable/version"
|
||||
require_relative "action_cable/zeitwerk"
|
||||
Zeitwerk::Loader.for_gem.tap do |loader|
|
||||
loader.ignore(
|
||||
"#{__dir__}/rails", # Contains generators, templates, docs, etc.
|
||||
"#{__dir__}/action_cable/gem_version.rb"
|
||||
)
|
||||
|
||||
loader.do_not_eager_load(
|
||||
"#{__dir__}/action_cable/subscription_adapter", # Adapters are required and loaded on demand.
|
||||
"#{__dir__}/action_cable/test_helper.rb",
|
||||
Dir["#{__dir__}/action_cable/**/test_case.rb"]
|
||||
)
|
||||
|
||||
loader.inflector.inflect("postgresql" => "PostgreSQL")
|
||||
end.setup
|
||||
|
||||
module ActionCable
|
||||
require_relative "action_cable/version"
|
||||
|
||||
INTERNAL = {
|
||||
message_types: {
|
||||
welcome: "welcome",
|
||||
|
|
|
@ -1,32 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require "zeitwerk"
|
||||
|
||||
lib = File.expand_path("..", __dir__)
|
||||
|
||||
loader = Zeitwerk::Loader.new
|
||||
loader.tag = "action_cable"
|
||||
|
||||
loader.push_dir(lib)
|
||||
|
||||
loader.ignore(
|
||||
__FILE__,
|
||||
"#{lib}/action_cable/gem_version.rb",
|
||||
"#{lib}/action_cable/version.rb",
|
||||
# lib/rails contains generators, templates, documentation, etc. Generators are
|
||||
# required on demand, so we can just ignore it all.
|
||||
"#{lib}/rails",
|
||||
)
|
||||
|
||||
loader.do_not_eager_load(
|
||||
# Adapters are required and loaded on demand.
|
||||
"#{lib}/action_cable/subscription_adapter",
|
||||
"#{lib}/action_cable/test_helper.rb",
|
||||
"#{lib}/action_cable/test_case.rb",
|
||||
"#{lib}/action_cable/connection/test_case.rb",
|
||||
"#{lib}/action_cable/channel/test_case.rb"
|
||||
)
|
||||
|
||||
loader.inflector.inflect("postgresql" => "PostgreSQL")
|
||||
|
||||
loader.setup
|
Loading…
Reference in a new issue