dry-rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +13 -11
- data/lib/dry/rails/container.rb +9 -0
- data/lib/dry/rails/features/safe_params.rb +9 -3
- data/lib/dry/rails/railtie.rb +12 -5
- data/lib/dry/rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c3503a4784fff4602afd40a4617ec013c95a69b71308dabd5c2e8daf90901337
|
4
|
+
data.tar.gz: 271597c911b36d298bc741350abf4ae8c8f78e2c41f6ae2a0bfe467fb2666eba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 801d04d9a2d3860c790ff3a5e7f8f0573bb9432c7d26ba62e833915b85f46021930ad08821c04271c51ee2c1cd82a8fe7031fbe27053e15c8df81fe4d84e4232
|
7
|
+
data.tar.gz: 9bbb63b8b0f50ceef021dd2dbc5a0d65dae979c9f239a39e68215619c85cf18a6445db8f0f618c8c2c7f48b1de2a344a547e763009dc9ebf32e1c3c411c5b904
|
data/CHANGELOG.md
CHANGED
@@ -1,26 +1,28 @@
|
|
1
1
|
## unreleased
|
2
2
|
|
3
|
-
Initial port of dry-system-rails with a couple of new features
|
4
3
|
|
5
4
|
### Added
|
6
5
|
|
7
|
-
-
|
8
|
-
- `config.features` setting which is an array with feature identifiers that you want the railtie to boot (@solnic)
|
9
|
-
- `:application_contract` feature which defines `ApplicationContract` within the application namespace and configured to work with `I18n` (@solnic)
|
10
|
-
- `:safe_params` feature which extends `ApplicationController` with `schema` DSL and exposes `safe_params` controller helper (@solnic)
|
11
|
-
- `:controller_helper` feature which adds `ApplicationController#{resolve,container}` shortcuts (@solnic)
|
6
|
+
- You can now configure auto_inject constant name via `config.auto_inject_constant` - previously it was hardcoded as `"Import"`, now it's configured as `"Deps"` by default (issue #18 closed via #29) (@diegotoral)
|
12
7
|
|
8
|
+
### Fixed
|
13
9
|
|
14
|
-
|
10
|
+
- Resolving `Container` constant looks it up only within the application namespace (see #22 for more information) (@jandudulski)
|
11
|
+
- [safe_params] defining multiple schemas works as expected (issue #23 fixed via 24) (@gotar)
|
15
12
|
|
16
|
-
|
13
|
+
### Changed
|
14
|
+
|
15
|
+
- The `:env` dry-system plugin is now enabled by default (fixes #28 via #30) (@solnic)
|
16
|
+
|
17
|
+
[Compare v0.1.0...master](https://github.com/dry-rb/dry-rails/compare/v0.1.0...master)
|
18
|
+
|
19
|
+
## 0.1.0 2020-03-30
|
17
20
|
|
18
|
-
|
21
|
+
This is based on dry-system-rails that dry-rails replaces.
|
19
22
|
|
20
23
|
### Added
|
21
24
|
|
22
|
-
- `:rails` system component provider, which uses standard bootable components, aka "features", to manage application state (@solnic)
|
23
25
|
- `config.features` setting which is an array with feature identifiers that you want the railtie to boot (@solnic)
|
24
26
|
- `:application_contract` feature which defines `ApplicationContract` within the application namespace and configured to work with `I18n` (@solnic)
|
25
27
|
- `:safe_params` feature which extends `ApplicationController` with `schema` DSL and exposes `safe_params` controller helper (@solnic)
|
26
|
-
- `:
|
28
|
+
- `:controller_helpers` feature which adds `ApplicationController#{resolve,container}` shortcuts (@solnic)
|
data/lib/dry/rails/container.rb
CHANGED
@@ -41,6 +41,15 @@ module Dry
|
|
41
41
|
# @!scope class
|
42
42
|
setting :auto_register_paths, [].freeze, reader: true
|
43
43
|
|
44
|
+
# @overload config.auto_inject_constant=(auto_inject_constant)
|
45
|
+
# Set a custom import constant name
|
46
|
+
#
|
47
|
+
# @param auto_inject_constant [String]
|
48
|
+
#
|
49
|
+
# @api public
|
50
|
+
# @!scope class
|
51
|
+
setting :auto_inject_constant, "Deps", reader: true
|
52
|
+
|
44
53
|
# @!endgroup
|
45
54
|
|
46
55
|
# The railtie has a rails-specific auto-registrar which is app-dir aware
|
@@ -13,6 +13,10 @@ module Dry
|
|
13
13
|
def self.included(klass)
|
14
14
|
super
|
15
15
|
klass.extend(ClassMethods)
|
16
|
+
|
17
|
+
klass.class_eval do
|
18
|
+
before_action(:set_safe_params, prepend: true)
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
# ApplicationController methods
|
@@ -33,8 +37,6 @@ module Dry
|
|
33
37
|
schemas[name] = schema
|
34
38
|
end
|
35
39
|
|
36
|
-
before_action(:set_safe_params, only: actions)
|
37
|
-
|
38
40
|
self
|
39
41
|
end
|
40
42
|
|
@@ -68,7 +70,11 @@ module Dry
|
|
68
70
|
|
69
71
|
# @api private
|
70
72
|
def set_safe_params
|
71
|
-
|
73
|
+
schema = schemas[action_name.to_sym]
|
74
|
+
|
75
|
+
return unless schema
|
76
|
+
|
77
|
+
@safe_params = schema.(request.params)
|
72
78
|
end
|
73
79
|
end
|
74
80
|
end
|
data/lib/dry/rails/railtie.rb
CHANGED
@@ -16,10 +16,12 @@ module Dry
|
|
16
16
|
|
17
17
|
# Code-reloading-aware finalization process
|
18
18
|
#
|
19
|
-
# This sets up `Container` and `
|
19
|
+
# This sets up `Container` and `Deps` constants, reloads them if this is in reloading mode,
|
20
20
|
# and registers default components like the railtie itself or the inflector
|
21
21
|
#
|
22
22
|
# @api public
|
23
|
+
#
|
24
|
+
# rubocop:disable Metrics/AbcSize
|
23
25
|
def finalize!
|
24
26
|
stop_features if reloading?
|
25
27
|
|
@@ -33,14 +35,18 @@ module Dry
|
|
33
35
|
system_dir: root_path.join("config/system")
|
34
36
|
)
|
35
37
|
|
38
|
+
# Enable :env plugin by default because it is a very common requirement
|
39
|
+
container.use :env, inferrer: -> { ::Rails.env }
|
40
|
+
|
36
41
|
container.register(:railtie, self)
|
37
42
|
container.register(:inflector, default_inflector)
|
38
43
|
|
39
44
|
set_or_reload(:Container, container)
|
40
|
-
set_or_reload(:Import, container.injector)
|
41
45
|
|
42
46
|
Dry::Rails.evaluate_initializer(container)
|
43
47
|
|
48
|
+
set_or_reload(container.auto_inject_constant, container.injector)
|
49
|
+
|
44
50
|
container.features.each do |feature|
|
45
51
|
container.boot(feature, from: :rails)
|
46
52
|
end
|
@@ -49,6 +55,7 @@ module Dry
|
|
49
55
|
|
50
56
|
container.finalize!(freeze: !::Rails.env.test?)
|
51
57
|
end
|
58
|
+
# rubocop:enable Metrics/AbcSize
|
52
59
|
alias_method :reload, :finalize!
|
53
60
|
|
54
61
|
# Stops all configured features (bootable components)
|
@@ -70,14 +77,14 @@ module Dry
|
|
70
77
|
#
|
71
78
|
# @api public
|
72
79
|
def container
|
73
|
-
app_namespace.const_get(:Container)
|
80
|
+
app_namespace.const_get(:Container, false)
|
74
81
|
end
|
75
82
|
|
76
83
|
# Return true if we're in code-reloading mode
|
77
84
|
#
|
78
85
|
# @api private
|
79
86
|
def reloading?
|
80
|
-
app_namespace.const_defined?(:Container)
|
87
|
+
app_namespace.const_defined?(:Container, false)
|
81
88
|
end
|
82
89
|
|
83
90
|
# Return the default system name
|
@@ -118,7 +125,7 @@ module Dry
|
|
118
125
|
|
119
126
|
# @api private
|
120
127
|
def set_or_reload(const_name, const)
|
121
|
-
if app_namespace.const_defined?(const_name)
|
128
|
+
if app_namespace.const_defined?(const_name, false)
|
122
129
|
app_namespace.__send__(:remove_const, const_name)
|
123
130
|
end
|
124
131
|
|
data/lib/dry/rails/version.rb
CHANGED
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.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2020-07-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-schema
|