Skip to content

Commit d3a0f67

Browse files
committed
Add support for dry-system 0.20.0
1 parent 3f787c3 commit d3a0f67

File tree

15 files changed

+53
-174
lines changed

15 files changed

+53
-174
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ jobs:
2828
- "3.0"
2929
- "2.7"
3030
- "2.6"
31-
- "2.5"
32-
- "jruby"
3331
include:
3432
- ruby: "3.0"
3533
coverage: "true"

docsite/source/index.html.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,10 @@ Currently, the railtie **does not make any assumptions about your directory/file
4949
```ruby
5050
# config/initializers/system.rb
5151
Dry::Rails.container do
52-
auto_register!("app/operations")
52+
config.component_dirs.add "app/operations"
53+
config.component_dirs.add "lib" do |dir|
54+
dir.default_namespace = "my_super_cool_app"
55+
end
5356
end
5457
```
5558

dry-rails.gemspec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Gem::Specification.new do |spec|
2929
spec.required_ruby_version = ">= 2.6.0"
3030

3131
# to update dependencies edit project.yml
32-
spec.add_runtime_dependency "dry-schema", "~> 1.5"
33-
spec.add_runtime_dependency "dry-system", "~> 0.18.0", ">= 0.18.1"
34-
spec.add_runtime_dependency "dry-validation", "~> 1.5"
32+
spec.add_runtime_dependency "dry-schema", "~> 1.8"
33+
spec.add_runtime_dependency "dry-system", "~> 0.20.0", ">= 0.18.1"
34+
spec.add_runtime_dependency "dry-validation", "~> 1.7"
3535

3636
spec.add_development_dependency "bundler"
3737
spec.add_development_dependency "rake"

lib/dry/rails.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ module Dry
1111
# # config/initializer/system.rb
1212
#
1313
# Dry::Rails.container do
14-
# auto_register!("lib", "app/operations")
15-
# end
14+
# config.component_dirs.add "lib" do |dir|
15+
# dir.default_namespace = "my_super_cool_app"
16+
# end
1617
#
17-
# @see Dry::Rails::Container.auto_register!
18+
# config.component_dirs.add "app/operations"
19+
# end
1820
#
1921
# @api public
2022
module Rails

lib/dry/rails/container.rb

Lines changed: 9 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,9 @@ class Container < System::Container
2727
#
2828
# @api public
2929
# @!scope class
30-
setting :features, %i[application_contract safe_params controller_helpers], reader: true
31-
32-
# @overload config.auto_register_paths=(paths)
33-
# Set an array of path/block pairs for auto-registration
34-
#
35-
# This is a low-level setting that typically should not be set explicitly,
36-
# use `auto_register!` instead.
37-
#
38-
# @param paths [Array<Array>]
39-
#
40-
# @api public
41-
# @!scope class
42-
setting :auto_register_paths, [].freeze, reader: true
30+
setting :features,
31+
default: %i[application_contract safe_params controller_helpers],
32+
reader: true
4333

4434
# @overload config.auto_inject_constant=(auto_inject_constant)
4535
# Set a custom import constant name
@@ -48,7 +38,9 @@ class Container < System::Container
4838
#
4939
# @api public
5040
# @!scope class
51-
setting :auto_inject_constant, "Deps", reader: true
41+
setting :auto_inject_constant,
42+
default: "Deps",
43+
reader: true
5244

5345
# @overload config.container_constant=(container_constant)
5446
# Set a custom container constant
@@ -57,90 +49,16 @@ class Container < System::Container
5749
#
5850
# @api public
5951
# @!scope class
60-
setting :container_constant, "Container", reader: true
52+
setting :container_constant,
53+
default: "Container",
54+
reader: true
6155

6256
# @!endgroup
6357

6458
# The railtie has a rails-specific auto-registrar which is app-dir aware
6559
config.auto_registrar = Rails::AutoRegistrars::App
6660

6761
class << self
68-
# Set up auto-registration paths and optional a configuration block
69-
#
70-
# @example set up a single path
71-
# Dry::Rails.container do
72-
# auto_register!("app/operations")
73-
# end
74-
#
75-
# @example set up a single path with a configuration block
76-
# Dry::Rails.container do
77-
# auto_register!("app/operations") do |config|
78-
# config.exclude do |component|
79-
# component.path.start_with?("concerns")
80-
# end
81-
# end
82-
# end
83-
#
84-
# @example set up multiple paths
85-
# Dry::Rails.container do
86-
# auto_register!("lib", "app/operations")
87-
# end
88-
#
89-
# @example set up multiple paths with a configuration block
90-
# Dry::Rails.container do
91-
# # in this case the config block will be applied to all paths
92-
# auto_register!("lib", "app/operations") do |config|
93-
# config.exclude do |component|
94-
# component.path.start_with?("concerns")
95-
# end
96-
# end
97-
# end
98-
#
99-
# @param paths [Array<String>] One or more paths relative to the root
100-
# @param set_load_paths [Boolean] Whether the paths should be added to $LOAD_PATH
101-
# @param load_files [Boolean] Whether files should be `required`-ed already
102-
#
103-
# @return [self]
104-
#
105-
# @api public
106-
#
107-
# TODO: this should be moved to dry-system
108-
def auto_register!(*paths, set_load_paths: true, load_files: false, &block)
109-
load_paths!(*paths) if set_load_paths
110-
111-
if load_files
112-
paths.each { |path| super(path, &block) }
113-
else
114-
config.auto_register_paths.concat(paths.product([block]))
115-
end
116-
117-
self
118-
end
119-
120-
# Finalize the container
121-
#
122-
# This is called automatically via the railtie, so typically you won't be using this method
123-
# directly
124-
#
125-
# @param freeze [Boolean] Whether the container should be frozen upon finalization
126-
#
127-
# @return [self]
128-
#
129-
# @api public
130-
#
131-
# TODO: just like auto_register!, this should be moved to dry-system
132-
def finalize!(freeze: false, &block)
133-
features.each do |feature|
134-
start(feature)
135-
end
136-
137-
auto_register_paths.each do |(path, path_block)|
138-
auto_register!(path, set_load_paths: false, load_files: true, &path_block)
139-
end
140-
141-
super
142-
end
143-
14462
# Return if a given component was booted
14563
#
14664
# @return [Boolean]

lib/dry/rails/railtie.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ def finalize!
3333

3434
container = Dry::Rails.create_container(
3535
root: root_path,
36-
name: name,
37-
default_namespace: name.to_s,
3836
inflector: default_inflector,
3937
system_dir: root_path.join("config/system"),
4038
bootable_dirs: [root_path.join("config/system/boot")]

spec/dummy-6.x/dummy/config/environments/test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# Configure public file server for tests with Cache-Control for performance.
1919
config.public_file_server.enabled = true
2020
config.public_file_server.headers = {
21-
"Cache-Control" => "public, max-age=#{1.hour.to_i}"
21+
"Cache-Control" => "public, max-age=3600"
2222
}
2323

2424
# Show full error reports and disable caching.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# frozen_string_literal: true
2+
3+
class CreateUserForm
4+
end

spec/dummy/config/initializers/system.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,13 @@
33
require "dry/rails"
44

55
Dry::Rails.container do
6-
auto_register!("lib")
6+
config.component_dirs.add "lib" do |dir|
7+
dir.default_namespace = "dummy"
8+
end
9+
10+
config.component_dirs.add "app/operations"
11+
config.component_dirs.add "app/services"
12+
config.component_dirs.add("app/workers") do |dir|
13+
dir.memoize = true
14+
end
715
end

spec/integration/dry/rails/container/auto_register/with_block_spec.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)