dry-rails 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1c8bf91377bb340114bf15b0eaacb6972059cff82d019e8dbb4afc753ff1e12f
4
- data.tar.gz: d0e546b39118fda74c34f79ac6155d7d91a013b3e6524e7281185098abd1ef0b
3
+ metadata.gz: 315efa0b4975c1afe8c02e36ad325eda687c505cbeec76329eaf330f229d21f2
4
+ data.tar.gz: 0ee2ec74bafce16a2cee710fb90c10bb483b672f1178fbd76a4518c7d12d98ea
5
5
  SHA512:
6
- metadata.gz: 8611b66718b3cfa1d5df6f21916444defa107bdf8fe781df3797cdc0630c82e1e1faa9f109f6ed3d028888f02554997d8e48749451f8a1233d27ba3ccd8fcdd3
7
- data.tar.gz: 36e0861dbbd1e858d44e148b16af49ec629c6580f9169f0df70abd8d49d3ebe5dbb59dcda7183dda4375c440395e999428358d6f21c1b328ce87edb961e0a482
6
+ metadata.gz: acd9f6bda792c65ee94b92d6e62ba286f33c2f3b4d7c01fa7f2b7818954fa61c52705686fa919091174ef6de8172d2dfb9b68077bf6f8a866a8fd19e10129290
7
+ data.tar.gz: 8001793ca368b1dc0388cacd2610441082a22163ec209169194be1d84aaa1ad5b83b8b6d3d45ea395eac29b5e1bb532296a425dac1664de91675f74a47794a7b
data/CHANGELOG.md CHANGED
@@ -1,3 +1,23 @@
1
+ <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
2
+
3
+ ## 0.4.0 2021-12-23
4
+
5
+ This is a big update - please also read dry-system [CHANGELOG](https://github.com/dry-rb/dry-system/blob/master/CHANGELOG.md) versions 0.20 and 0.21.
6
+
7
+ ### Added
8
+
9
+ - It's now possible to configure container constant name via `config.constainer_const_name` (issue #21 closed via #41) (@diegotoral)
10
+
11
+ ### Fixed
12
+
13
+ - `config.auto_inject_constant` is now cleared during code reloading (see #40 for more info) (@diegotoral)
14
+
15
+ ### Changed
16
+
17
+ - Updated to work with dry-system 0.21 (via #48 and #50) (@zlw + @solnic)
18
+
19
+ [Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-rails/compare/v0.3.0...v0.4.0)
20
+
1
21
  ## 0.3.0 2020-08-26
2
22
 
3
23
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2020 dry-rb team
3
+ Copyright (c) 2015-2021 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
+ <!--- this file is synced from dry-rb/template-gem project -->
1
2
  [gem]: https://rubygems.org/gems/dry-rails
2
3
  [actions]: https://github.com/dry-rb/dry-rails/actions
3
4
  [codacy]: https://www.codacy.com/gh/dry-rb/dry-rails
@@ -7,23 +8,22 @@
7
8
  # dry-rails [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
8
9
 
9
10
  [![Gem Version](https://badge.fury.io/rb/dry-rails.svg)][gem]
10
- [![CI Status](https://github.com/dry-rb/dry-rails/workflows/ci/badge.svg)][actions]
11
+ [![CI Status](https://github.com/dry-rb/dry-rails/workflows/CI/badge.svg)][actions]
11
12
  [![Codacy Badge](https://api.codacy.com/project/badge/Grade/d4677ea0c4c2497bb1af1b3ac31552f4)][codacy]
12
13
  [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/d4677ea0c4c2497bb1af1b3ac31552f4)][codacy]
13
14
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-rails.svg?branch=master)][inchpages]
14
15
 
15
- dry-rails provides the official integration of dry-rb gems with Ruby on Rails framework.
16
16
  ## Links
17
17
 
18
- * [User documentation](http://dry-rb.org/gems/dry-rails)
18
+ * [User documentation](https://dry-rb.org/gems/dry-rails)
19
19
  * [API documentation](http://rubydoc.info/gems/dry-rails)
20
20
 
21
21
  ## Supported Ruby versions
22
22
 
23
23
  This library officially supports the following Ruby versions:
24
24
 
25
- * MRI >= `2.4`
26
- * jruby >= `9.2`
25
+ * MRI `>= 2.6.0`
26
+ * jruby `>= 9.3`
27
27
 
28
28
  ## License
29
29
 
data/dry-rails.gemspec CHANGED
@@ -1,35 +1,36 @@
1
1
  # frozen_string_literal: true
2
- # this file is managed by dry-rb/devtools project
3
2
 
4
- lib = File.expand_path('lib', __dir__)
3
+ # this file is synced from dry-rb/template-gem project
4
+
5
+ lib = File.expand_path("lib", __dir__)
5
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
- require 'dry/rails/version'
7
+ require "dry/rails/version"
7
8
 
8
9
  Gem::Specification.new do |spec|
9
- spec.name = 'dry-rails'
10
+ spec.name = "dry-rails"
10
11
  spec.authors = ["Piotr Solnica"]
11
12
  spec.email = ["piotr.solnica@gmail.com"]
12
- spec.license = 'MIT'
13
+ spec.license = "MIT"
13
14
  spec.version = Dry::Rails::VERSION.dup
14
15
 
15
16
  spec.summary = "The official dry-rb railtie for Ruby on Rails"
16
17
  spec.description = "dry-rails provides the official integration of dry-rb gems with Ruby on Rails framework."
17
- spec.homepage = 'https://dry-rb.org/gems/dry-rails'
18
+ spec.homepage = "https://dry-rb.org/gems/dry-rails"
18
19
  spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-rails.gemspec", "lib/**/*"]
19
- spec.bindir = 'bin'
20
+ spec.bindir = "bin"
20
21
  spec.executables = []
21
- spec.require_paths = ['lib']
22
+ spec.require_paths = ["lib"]
22
23
 
23
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
- spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-rails/blob/master/CHANGELOG.md'
25
- spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-rails'
26
- spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-rails/issues'
24
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-rails/blob/master/CHANGELOG.md"
26
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-rails"
27
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-rails/issues"
27
28
 
28
- spec.required_ruby_version = ">= 2.4.0"
29
+ spec.required_ruby_version = ">= 2.6.0"
29
30
 
30
31
  # to update dependencies edit project.yml
31
- spec.add_runtime_dependency "dry-schema", "~> 1.5"
32
- spec.add_runtime_dependency "dry-system", "~> 0.18.0", ">= 0.18.1"
32
+ spec.add_runtime_dependency "dry-schema", "~> 1.7"
33
+ spec.add_runtime_dependency "dry-system", "~> 0.21"
33
34
  spec.add_runtime_dependency "dry-validation", "~> 1.5"
34
35
 
35
36
  spec.add_development_dependency "bundler"
@@ -27,28 +27,31 @@ module Dry
27
27
  #
28
28
  # @api public
29
29
  # @!scope class
30
- setting :features, %i[application_contract safe_params controller_helpers], reader: true
30
+ setting :features,
31
+ default: %i[application_contract safe_params controller_helpers],
32
+ reader: true
31
33
 
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.
34
+ # @overload config.auto_inject_constant=(auto_inject_constant)
35
+ # Set a custom import constant name
37
36
  #
38
- # @param paths [Array<Array>]
37
+ # @param auto_inject_constant [String]
39
38
  #
40
39
  # @api public
41
40
  # @!scope class
42
- setting :auto_register_paths, [].freeze, reader: true
41
+ setting :auto_inject_constant,
42
+ default: "Deps",
43
+ reader: true
43
44
 
44
- # @overload config.auto_inject_constant=(auto_inject_constant)
45
- # Set a custom import constant name
45
+ # @overload config.container_constant=(container_constant)
46
+ # Set a custom container constant
46
47
  #
47
- # @param auto_inject_constant [String]
48
+ # @param container_constant [String]
48
49
  #
49
50
  # @api public
50
51
  # @!scope class
51
- setting :auto_inject_constant, "Deps", reader: true
52
+ setting :container_constant,
53
+ default: "Container",
54
+ reader: true
52
55
 
53
56
  # @!endgroup
54
57
 
@@ -56,82 +59,6 @@ module Dry
56
59
  config.auto_registrar = Rails::AutoRegistrars::App
57
60
 
58
61
  class << self
59
- # Set up auto-registration paths and optional a configuration block
60
- #
61
- # @example set up a single path
62
- # Dry::Rails.container do
63
- # auto_register!("app/operations")
64
- # end
65
- #
66
- # @example set up a single path with a configuration block
67
- # Dry::Rails.container do
68
- # auto_register!("app/operations") do |config|
69
- # config.exclude do |component|
70
- # component.path.start_with?("concerns")
71
- # end
72
- # end
73
- # end
74
- #
75
- # @example set up multiple paths
76
- # Dry::Rails.container do
77
- # auto_register!("lib", "app/operations")
78
- # end
79
- #
80
- # @example set up multiple paths with a configuration block
81
- # Dry::Rails.container do
82
- # # in this case the config block will be applied to all paths
83
- # auto_register!("lib", "app/operations") do |config|
84
- # config.exclude do |component|
85
- # component.path.start_with?("concerns")
86
- # end
87
- # end
88
- # end
89
- #
90
- # @param paths [Array<String>] One or more paths relative to the root
91
- # @param set_load_paths [Boolean] Whether the paths should be added to $LOAD_PATH
92
- # @param load_files [Boolean] Whether files should be `required`-ed already
93
- #
94
- # @return [self]
95
- #
96
- # @api public
97
- #
98
- # TODO: this should be moved to dry-system
99
- def auto_register!(*paths, set_load_paths: true, load_files: false, &block)
100
- load_paths!(*paths) if set_load_paths
101
-
102
- if load_files
103
- paths.each { |path| super(path, &block) }
104
- else
105
- config.auto_register_paths.concat(paths.product([block]))
106
- end
107
-
108
- self
109
- end
110
-
111
- # Finalize the container
112
- #
113
- # This is called automatically via the railtie, so typically you won't be using this method
114
- # directly
115
- #
116
- # @param freeze [Boolean] Whether the container should be frozen upon finalization
117
- #
118
- # @return [self]
119
- #
120
- # @api public
121
- #
122
- # TODO: just like auto_register!, this should be moved to dry-system
123
- def finalize!(freeze: false, &block)
124
- features.each do |feature|
125
- start(feature)
126
- end
127
-
128
- auto_register_paths.each do |(path, path_block)|
129
- auto_register!(path, set_load_paths: false, load_files: true, &path_block)
130
- end
131
-
132
- super
133
- end
134
-
135
62
  # Return if a given component was booted
136
63
  #
137
64
  # @return [Boolean]
@@ -140,7 +67,7 @@ module Dry
140
67
  #
141
68
  # TODO: this should be moved to dry-system
142
69
  def booted?(name)
143
- booter.booted.map(&:identifier).include?(name)
70
+ booter.booted.map(&:name).include?(name)
144
71
  end
145
72
 
146
73
  # TODO: confirm that this is really needed
@@ -8,6 +8,8 @@ module Dry
8
8
  #
9
9
  # @api public
10
10
  class Railtie < ::Rails::Railtie
11
+ attr_reader :container_const_name
12
+
11
13
  # This is needed because `finalize!` can reload code and this hook is called every-time
12
14
  # in development env upon a request (in production it's called just once during booting)
13
15
  config.to_prepare do
@@ -23,14 +25,14 @@ module Dry
23
25
  #
24
26
  # rubocop:disable Metrics/AbcSize
25
27
  def finalize!
28
+ @container_const_name ||= Dry::Rails::Container.container_constant
29
+
26
30
  stop_features if reloading?
27
31
 
28
32
  root_path = ::Rails.root
29
33
 
30
34
  container = Dry::Rails.create_container(
31
35
  root: root_path,
32
- name: name,
33
- default_namespace: name.to_s,
34
36
  inflector: default_inflector,
35
37
  system_dir: root_path.join("config/system"),
36
38
  bootable_dirs: [root_path.join("config/system/boot")]
@@ -42,10 +44,16 @@ module Dry
42
44
  container.register(:railtie, self)
43
45
  container.register(:inflector, default_inflector)
44
46
 
45
- set_or_reload(:Container, container)
47
+ # Remove previously defined constants, if any, so we don't end up with
48
+ # unsused constants in app's namespace when a name change happens.
49
+ remove_constant(container.auto_inject_constant)
50
+ remove_constant(container.container_constant)
46
51
 
47
52
  Dry::Rails.evaluate_initializer(container)
48
53
 
54
+ @container_const_name = container.container_constant
55
+
56
+ set_or_reload(container.container_constant, container)
49
57
  set_or_reload(container.auto_inject_constant, container.injector)
50
58
 
51
59
  container.features.each do |feature|
@@ -78,14 +86,14 @@ module Dry
78
86
  #
79
87
  # @api public
80
88
  def container
81
- app_namespace.const_get(:Container, false)
89
+ app_namespace.const_get(container_const_name, false)
82
90
  end
83
91
 
84
92
  # Return true if we're in code-reloading mode
85
93
  #
86
94
  # @api private
87
95
  def reloading?
88
- app_namespace.const_defined?(:Container, false)
96
+ app_namespace.const_defined?(container_const_name, false)
89
97
  end
90
98
 
91
99
  # Return the default system name
@@ -126,16 +134,15 @@ module Dry
126
134
 
127
135
  # @api private
128
136
  def set_or_reload(const_name, const)
129
- if app_namespace.const_defined?(const_name, false)
130
- app_namespace.__send__(:remove_const, const_name)
131
- end
132
-
137
+ remove_constant(const_name)
133
138
  app_namespace.const_set(const_name, const)
134
139
  end
135
140
 
136
141
  # @api private
137
142
  def remove_constant(const_name)
138
- app_namespace.__send__(:remove_const, const_name)
143
+ if app_namespace.const_defined?(const_name, false)
144
+ app_namespace.__send__(:remove_const, const_name)
145
+ end
139
146
  end
140
147
  end
141
148
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Rails
5
- VERSION = "0.3.0"
5
+ VERSION = "0.4.0"
6
6
  end
7
7
  end
data/lib/dry/rails.rb CHANGED
@@ -11,10 +11,12 @@ module Dry
11
11
  # # config/initializer/system.rb
12
12
  #
13
13
  # Dry::Rails.container do
14
- # auto_register!("lib", "app/operations")
15
- # end
14
+ # config.component_dirs.add "lib" do |dir|
15
+ # dir.namespaces.add "my_super_cool_app", key: nil
16
+ # end
16
17
  #
17
- # @see Dry::Rails::Container.auto_register!
18
+ # config.component_dirs.add "app/operations"
19
+ # end
18
20
  #
19
21
  # @api public
20
22
  module Rails
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Piotr Solnica
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-26 00:00:00.000000000 Z
11
+ date: 2021-12-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-schema
@@ -16,34 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: '1.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.5'
26
+ version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: dry-system
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.18.0
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 0.18.1
33
+ version: '0.21'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
- version: 0.18.0
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 0.18.1
40
+ version: '0.21'
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: dry-validation
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -141,14 +135,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
141
135
  requirements:
142
136
  - - ">="
143
137
  - !ruby/object:Gem::Version
144
- version: 2.4.0
138
+ version: 2.6.0
145
139
  required_rubygems_version: !ruby/object:Gem::Requirement
146
140
  requirements:
147
141
  - - ">="
148
142
  - !ruby/object:Gem::Version
149
143
  version: '0'
150
144
  requirements: []
151
- rubygems_version: 3.0.3
145
+ rubygems_version: 3.1.6
152
146
  signing_key:
153
147
  specification_version: 4
154
148
  summary: The official dry-rb railtie for Ruby on Rails