Skip to content

Commit f9fc522

Browse files
committed
Use Zeitwerk for loading components
- Replace AutoRegistration with a new Loader that uses Zeitwerk - Deprecate `ROM::Setup#auto_registration` and move it to `rom/compat` Refs #607
1 parent 6f3c47a commit f9fc522

File tree

57 files changed

+588
-53
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+588
-53
lines changed

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ gem "rom-sql", github: "rom-rb/rom-sql", branch: "master"
1919
gem "dry-monitor", github: "dry-rb/dry-monitor", branch: "master"
2020
gem "dry-events", github: "dry-rb/dry-events", branch: "master"
2121

22+
gem "zeitwerk", github: "fxn/zeitwerk", branch: "main"
23+
2224
group :sql do
2325
gem "jdbc-postgres", platforms: :jruby
2426
gem "jdbc-sqlite3", platforms: :jruby

Rakefile

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ require "bundler/gem_tasks"
55
require "rspec/core"
66
require "rspec/core/rake_task"
77

8-
RSpec::Core::RakeTask.new(:spec)
8+
RSpec::Core::RakeTask.new("spec:all") do |t|
9+
t.pattern = ["spec/unit/**/*_spec.rb", "spec/integration/**/*_spec.rb"]
10+
end
11+
12+
RSpec::Core::RakeTask.new("spec:compat") do |t|
13+
t.pattern = ["spec/compat/**/*_spec.rb"]
14+
end
15+
16+
task "spec" => ["spec:all", "spec:compat"]
917

1018
task default: :spec
1119

@@ -25,8 +33,10 @@ namespace :benchmark do
2533
end
2634
end
2735

36+
# rubocop:disable Lint/SuppressedException
2837
begin
2938
require "yard-junk/rake"
3039
YardJunk::Rake.define_task(:text)
3140
rescue LoadError
3241
end
42+
# rubocop:enable Lint/SuppressedException

docsite/core/source/framework-setup.html.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ module Persistence
6565
end
6666

6767
configuration = ROM::Configuration.new(:memory)
68-
configuration.auto_registration('root_dir/lib/persistence/')
68+
configuration.auto_register('root_dir/lib/persistence/')
6969
container = ROM.container(configuration)
7070
```
7171

@@ -92,7 +92,7 @@ Notice that the directory structure is different from our module structure. Sinc
9292

9393
```ruby
9494
configuration = ROM::Configuration.new(:memory)
95-
configuration.auto_registration('/path/to/lib', namespace: 'Persistence')
95+
configuration.auto_register('/path/to/lib', namespace: 'Persistence')
9696
container = ROM.container(configuration)
9797
```
9898

@@ -146,7 +146,7 @@ end
146146
Then, auto-registration can be achieved with
147147

148148
```ruby
149-
configuration.auto_registration('/path/to/lib', namespace: 'MyApp::Persistence')
149+
configuration.auto_register('/path/to/lib', namespace: 'MyApp::Persistence')
150150
```
151151

152152
#### Turning namespace off
@@ -162,7 +162,7 @@ end
162162
163163
```ruby
164164
configuration = ROM::Configuration.new(:memory)
165-
configuration.auto_registration('/path/to/lib', namespace: false)
165+
configuration.auto_register('/path/to/lib', namespace: false)
166166
container = ROM.container(configuration)
167167
```
168168

lib/rom/compat.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "compat/setup"

lib/rom/setup/auto_registration.rb renamed to lib/rom/compat/auto_registration.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66

77
require "rom/types"
88
require "rom/initializer"
9-
require "rom/setup/auto_registration_strategies/no_namespace"
10-
require "rom/setup/auto_registration_strategies/with_namespace"
11-
require "rom/setup/auto_registration_strategies/custom_namespace"
9+
10+
require_relative "auto_registration_strategies/no_namespace"
11+
require_relative "auto_registration_strategies/with_namespace"
12+
require_relative "auto_registration_strategies/custom_namespace"
1213

1314
module ROM
1415
# AutoRegistration is used to load component files automatically from the provided directory path
File renamed without changes.

lib/rom/setup/auto_registration_strategies/custom_namespace.rb renamed to lib/rom/compat/auto_registration_strategies/custom_namespace.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44

55
require "rom/support/inflector"
66
require "rom/types"
7-
require "rom/setup/auto_registration_strategies/base"
7+
8+
require_relative "base"
89

910
module ROM
1011
module AutoRegistrationStrategies

lib/rom/setup/auto_registration_strategies/no_namespace.rb renamed to lib/rom/compat/auto_registration_strategies/no_namespace.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
require "rom/support/inflector"
66
require "rom/types"
7-
require "rom/setup/auto_registration_strategies/base"
7+
require_relative "base"
88

99
module ROM
1010
module AutoRegistrationStrategies

lib/rom/setup/auto_registration_strategies/with_namespace.rb renamed to lib/rom/compat/auto_registration_strategies/with_namespace.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
require "pathname"
44

55
require "rom/support/inflector"
6-
require "rom/setup/auto_registration_strategies/base"
6+
require_relative "base"
77

88
module ROM
99
module AutoRegistrationStrategies

lib/rom/compat/setup.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# frozen_string_literal: true
2+
3+
require_relative "auto_registration"
4+
5+
module ROM
6+
# Setup objects collect component classes during setup/finalization process
7+
#
8+
# @api public
9+
class Setup
10+
# Enable auto-registration for a given setup object
11+
#
12+
# @param [String, Pathname] directory The root path to components
13+
# @param [Hash] options
14+
# @option options [Boolean, String] :namespace Toggle root namespace
15+
# or provide a custom namespace name
16+
#
17+
# @return [Setup]
18+
#
19+
# @deprecated
20+
#
21+
# @api public
22+
def auto_registration(directory, **options)
23+
auto_registration = AutoRegistration.new(directory, inflector: inflector, **options)
24+
auto_registration.relations.map { |r| register_relation(r) }
25+
auto_registration.commands.map { |r| register_command(r) }
26+
auto_registration.mappers.map { |r| register_mapper(r) }
27+
self
28+
end
29+
end
30+
end

0 commit comments

Comments
 (0)