nano-lite-hub 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/dry-rails-0.7.0/CHANGELOG.md +101 -0
- data/dry-rails-0.7.0/LICENSE +20 -0
- data/dry-rails-0.7.0/README.md +22 -0
- data/dry-rails-0.7.0/dry-rails.gemspec +39 -0
- data/dry-rails-0.7.0/lib/dry/rails/auto_registrars/app.rb +31 -0
- data/dry-rails-0.7.0/lib/dry/rails/boot/application_contract.rb +19 -0
- data/dry-rails-0.7.0/lib/dry/rails/boot/controller_helpers.rb +15 -0
- data/dry-rails-0.7.0/lib/dry/rails/boot/safe_params.rb +15 -0
- data/dry-rails-0.7.0/lib/dry/rails/container.rb +91 -0
- data/dry-rails-0.7.0/lib/dry/rails/features/application_contract.rb +38 -0
- data/dry-rails-0.7.0/lib/dry/rails/features/controller_helpers.rb +40 -0
- data/dry-rails-0.7.0/lib/dry/rails/features/safe_params.rb +82 -0
- data/dry-rails-0.7.0/lib/dry/rails/railtie.rb +148 -0
- data/dry-rails-0.7.0/lib/dry/rails/version.rb +7 -0
- data/dry-rails-0.7.0/lib/dry/rails.rb +60 -0
- data/dry-rails-0.7.0/lib/dry-rails.rb +3 -0
- data/nano-lite-hub.gemspec +11 -0
- metadata +57 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7f44a08ddb67fc1596b3588627bb857b71512a88a2f537f96822907dc5a63e53
|
|
4
|
+
data.tar.gz: bafd9a8b78a39052eb99a4debe3d3827105e7b06eafbb1cb045c9317a4f8e881
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 4ec32f8a6bbe2f6404eee8e6cc5e6d19d49eb2ff7394a07d462c057551fe943b002e64ce918fcb51bf4093553a3cad6eda9ea414a670038292c03f507652ee31
|
|
7
|
+
data.tar.gz: 6c2884eb3a4adab427274183e6d21b3c62cf8d4341c01030da3fa01fe913148af81e27f7021726c39e9bc0a0e8a9d560b4e5d53f022d1e89810dbe9be8db0be6
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
|
2
|
+
|
|
3
|
+
## 0.7.0 2022-12-23
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Changed
|
|
7
|
+
|
|
8
|
+
- Bump dry-schema to `>= 0.13` (@solnic)
|
|
9
|
+
- Bump dry-validation to `>= 0.10` (@solnic)
|
|
10
|
+
- Bump dry-system to `~> 1.0` (@solnic)
|
|
11
|
+
|
|
12
|
+
[Compare v0.6.0...v0.7.0](https://github.com/dry-rb/dry-rails/compare/v0.6.0...v0.7.0)
|
|
13
|
+
|
|
14
|
+
## 0.6.0 2022-10-20
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- Upgrade to zeitwerkified dry-rb deps (issue #55 fixed via #56) (@solnic)
|
|
20
|
+
|
|
21
|
+
[Compare v0.5.0...v0.6.0](https://github.com/dry-rb/dry-rails/compare/v0.5.0...v0.6.0)
|
|
22
|
+
|
|
23
|
+
## 0.5.0 2022-02-11
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- dry-system dependency was bumped to >= 0.23 (via #52) (@solnic)
|
|
29
|
+
|
|
30
|
+
[Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-rails/compare/v0.4.0...v0.5.0)
|
|
31
|
+
|
|
32
|
+
## 0.4.0 2021-12-23
|
|
33
|
+
|
|
34
|
+
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.
|
|
35
|
+
|
|
36
|
+
### Added
|
|
37
|
+
|
|
38
|
+
- It's now possible to configure container constant name via `config.constainer_const_name` (issue #21 closed via #41) (@diegotoral)
|
|
39
|
+
|
|
40
|
+
### Fixed
|
|
41
|
+
|
|
42
|
+
- `config.auto_inject_constant` is now cleared during code reloading (see #40 for more info) (@diegotoral)
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
|
|
46
|
+
- Updated to work with dry-system 0.21 (via #48 and #50) (@zlw + @solnic)
|
|
47
|
+
- dry-system dependency was bumped to >= 0.23 (via #52) (@solnic)
|
|
48
|
+
|
|
49
|
+
[Compare v0.3.0...v0.4.0](https://github.com/dry-rb/dry-rails/compare/v0.3.0...v0.4.0)
|
|
50
|
+
|
|
51
|
+
## 0.3.0 2020-08-26
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
### Changed
|
|
55
|
+
|
|
56
|
+
- Use dry-system 0.18.0 and configure new `bootable_dirs` setting appropriately (@timriley in #38)
|
|
57
|
+
|
|
58
|
+
[Compare v0.2.1...v0.3.0](https://github.com/dry-rb/dry-rails/compare/v0.2.1...v0.3.0)
|
|
59
|
+
|
|
60
|
+
## 0.2.1 2020-08-26
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### Added
|
|
64
|
+
|
|
65
|
+
- Controller features now support `ActionControll::API` too (issue #35 closed via #36) (@rinaldifonseca)
|
|
66
|
+
|
|
67
|
+
### Fixed
|
|
68
|
+
|
|
69
|
+
- Fix dry-system dependency to 0.17.0, to avoid incompatibilities with 0.18.0 (@timriley)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
[Compare v0.2.0...v0.2.1](https://github.com/dry-rb/dry-rails/compare/v0.2.0...v0.2.1)
|
|
73
|
+
|
|
74
|
+
## 0.2.0 2020-07-21
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
### Added
|
|
78
|
+
|
|
79
|
+
- 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)
|
|
80
|
+
|
|
81
|
+
### Fixed
|
|
82
|
+
|
|
83
|
+
- Resolving `Container` constant looks it up only within the application namespace (see #22 for more information) (@jandudulski)
|
|
84
|
+
- [safe_params] defining multiple schemas works as expected (issue #23 fixed via 24) (@gotar)
|
|
85
|
+
|
|
86
|
+
### Changed
|
|
87
|
+
|
|
88
|
+
- The `:env` dry-system plugin is now enabled by default (fixes #28 via #30) (@solnic)
|
|
89
|
+
|
|
90
|
+
[Compare v0.1.0...v0.2.0](https://github.com/dry-rb/dry-rails/compare/v0.1.0...v0.2.0)
|
|
91
|
+
|
|
92
|
+
## 0.1.0 2020-03-30
|
|
93
|
+
|
|
94
|
+
This is based on dry-system-rails that dry-rails replaces.
|
|
95
|
+
|
|
96
|
+
### Added
|
|
97
|
+
|
|
98
|
+
- `config.features` setting which is an array with feature identifiers that you want the railtie to boot (@solnic)
|
|
99
|
+
- `:application_contract` feature which defines `ApplicationContract` within the application namespace and configured to work with `I18n` (@solnic)
|
|
100
|
+
- `:safe_params` feature which extends `ApplicationController` with `schema` DSL and exposes `safe_params` controller helper (@solnic)
|
|
101
|
+
- `:controller_helpers` feature which adds `ApplicationController#{resolve,container}` shortcuts (@solnic)
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015-2022 dry-rb team
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
|
7
|
+
the Software without restriction, including without limitation the rights to
|
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
10
|
+
subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!--- this file is synced from dry-rb/template-gem project -->
|
|
2
|
+
[gem]: https://rubygems.org/gems/dry-rails
|
|
3
|
+
[actions]: https://github.com/dry-rb/dry-rails/actions
|
|
4
|
+
|
|
5
|
+
# dry-rails [][gem] [][actions]
|
|
6
|
+
|
|
7
|
+
## Links
|
|
8
|
+
|
|
9
|
+
* [User documentation](https://dry-rb.org/gems/dry-rails)
|
|
10
|
+
* [API documentation](http://rubydoc.info/gems/dry-rails)
|
|
11
|
+
* [Forum](https://discourse.dry-rb.org)
|
|
12
|
+
|
|
13
|
+
## Supported Ruby versions
|
|
14
|
+
|
|
15
|
+
This library officially supports the following Ruby versions:
|
|
16
|
+
|
|
17
|
+
* MRI `>= 2.7.0`
|
|
18
|
+
* jruby `>= 9.3` (postponed until 2.7 is supported)
|
|
19
|
+
|
|
20
|
+
## License
|
|
21
|
+
|
|
22
|
+
See `LICENSE` file.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# this file is synced from dry-rb/template-gem project
|
|
4
|
+
|
|
5
|
+
lib = File.expand_path("lib", __dir__)
|
|
6
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
7
|
+
require "dry/rails/version"
|
|
8
|
+
|
|
9
|
+
Gem::Specification.new do |spec|
|
|
10
|
+
spec.name = "dry-rails"
|
|
11
|
+
spec.authors = ["Piotr Solnica"]
|
|
12
|
+
spec.email = ["piotr.solnica@gmail.com"]
|
|
13
|
+
spec.license = "MIT"
|
|
14
|
+
spec.version = Dry::Rails::VERSION.dup
|
|
15
|
+
|
|
16
|
+
spec.summary = "The official dry-rb railtie for Ruby on Rails"
|
|
17
|
+
spec.description = "dry-rails provides the official integration of dry-rb gems with Ruby on Rails framework."
|
|
18
|
+
spec.homepage = "https://dry-rb.org/gems/dry-rails"
|
|
19
|
+
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-rails.gemspec", "lib/**/*"]
|
|
20
|
+
spec.bindir = "bin"
|
|
21
|
+
spec.executables = []
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
25
|
+
spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-rails/blob/main/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"
|
|
28
|
+
|
|
29
|
+
spec.required_ruby_version = ">= 2.7.0"
|
|
30
|
+
|
|
31
|
+
# to update dependencies edit project.yml
|
|
32
|
+
spec.add_runtime_dependency "dry-schema", "~> 1.7"
|
|
33
|
+
spec.add_runtime_dependency "dry-system", "~> 1.0", "< 2"
|
|
34
|
+
spec.add_runtime_dependency "dry-validation", "~> 1.5"
|
|
35
|
+
|
|
36
|
+
spec.add_development_dependency "bundler"
|
|
37
|
+
spec.add_development_dependency "rake"
|
|
38
|
+
spec.add_development_dependency "rspec"
|
|
39
|
+
end
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "dry/system"
|
|
4
|
+
|
|
5
|
+
module Dry
|
|
6
|
+
module Rails
|
|
7
|
+
module AutoRegistrars
|
|
8
|
+
# This is the default auto-registrar configured in the Container
|
|
9
|
+
#
|
|
10
|
+
# @api private
|
|
11
|
+
class App < System::AutoRegistrar
|
|
12
|
+
# Resolve a path relative to the system root
|
|
13
|
+
#
|
|
14
|
+
# This works just like in `dry-system` except that it's app-dir aware. This means it will
|
|
15
|
+
# turn `app/operations/foo/bar` to `foo/bar` because app dirs are treated as root dirs.
|
|
16
|
+
#
|
|
17
|
+
# In a typical dry-system setup `app` would be the root and everything inside this path
|
|
18
|
+
# would indicate the constant hierachy, so `app/operations/foo/bar` => `Operations/Foo/Bar`
|
|
19
|
+
# but *this is not the Rails convention* so we need this special auto-registrar.
|
|
20
|
+
#
|
|
21
|
+
# @api private
|
|
22
|
+
def relative_path(dir, file_path)
|
|
23
|
+
path = super
|
|
24
|
+
return path unless dir.start_with?("app")
|
|
25
|
+
|
|
26
|
+
path.split("/")[1..-1].join("/")
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Dry::System.register_provider_source(:application_contract, group: :rails) do
|
|
4
|
+
prepare do
|
|
5
|
+
require "dry/rails/features/application_contract"
|
|
6
|
+
@railtie = target_container[:railtie]
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
start do
|
|
10
|
+
@railtie.set_or_reload(
|
|
11
|
+
:ApplicationContract,
|
|
12
|
+
Class.new(Dry::Rails::Features::ApplicationContract).finalize!(@railtie)
|
|
13
|
+
)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
stop do
|
|
17
|
+
@railtie.remove_constant(:ApplicationContract)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Dry::System.register_provider_source(:controller_helpers, group: :rails) do
|
|
4
|
+
prepare do
|
|
5
|
+
require "dry/rails/features/controller_helpers"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
start do
|
|
9
|
+
ApplicationController.include(Dry::Rails::Features::ControllerHelpers)
|
|
10
|
+
|
|
11
|
+
if defined?(ActionController::API)
|
|
12
|
+
ActionController::API.include(Dry::Rails::Features::ControllerHelpers)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Dry::System.register_provider_source(:safe_params, group: :rails) do
|
|
4
|
+
prepare do
|
|
5
|
+
require "dry/rails/features/safe_params"
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
start do
|
|
9
|
+
ApplicationController.include(Dry::Rails::Features::SafeParams)
|
|
10
|
+
|
|
11
|
+
if defined?(ActionController::API)
|
|
12
|
+
ActionController::API.include(Dry::Rails::Features::SafeParams)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/version"
|
|
4
|
+
|
|
5
|
+
require "dry/system"
|
|
6
|
+
require "dry/rails/auto_registrars/app"
|
|
7
|
+
|
|
8
|
+
module Dry
|
|
9
|
+
module Rails
|
|
10
|
+
# Customized Container class for Rails applications
|
|
11
|
+
#
|
|
12
|
+
# @api public
|
|
13
|
+
class Container < System::Container
|
|
14
|
+
# @!group Configuration
|
|
15
|
+
|
|
16
|
+
# @overload config.features=(features)
|
|
17
|
+
# Set an array of features that should be enabled by default
|
|
18
|
+
#
|
|
19
|
+
# Available values are:
|
|
20
|
+
# - application_contract
|
|
21
|
+
# - safe_params
|
|
22
|
+
# - controller_helpers
|
|
23
|
+
#
|
|
24
|
+
# @param features [Array<Symbol>]
|
|
25
|
+
#
|
|
26
|
+
# @api public
|
|
27
|
+
# @!scope class
|
|
28
|
+
setting :features,
|
|
29
|
+
default: %i[application_contract safe_params controller_helpers],
|
|
30
|
+
reader: true
|
|
31
|
+
|
|
32
|
+
# @overload config.auto_inject_constant=(auto_inject_constant)
|
|
33
|
+
# Set a custom import constant name
|
|
34
|
+
#
|
|
35
|
+
# @param auto_inject_constant [String]
|
|
36
|
+
#
|
|
37
|
+
# @api public
|
|
38
|
+
# @!scope class
|
|
39
|
+
setting :auto_inject_constant,
|
|
40
|
+
default: "Deps",
|
|
41
|
+
reader: true
|
|
42
|
+
|
|
43
|
+
# @overload config.container_constant=(container_constant)
|
|
44
|
+
# Set a custom container constant
|
|
45
|
+
#
|
|
46
|
+
# @param container_constant [String]
|
|
47
|
+
#
|
|
48
|
+
# @api public
|
|
49
|
+
# @!scope class
|
|
50
|
+
setting :container_constant,
|
|
51
|
+
default: "Container",
|
|
52
|
+
reader: true
|
|
53
|
+
|
|
54
|
+
# @!endgroup
|
|
55
|
+
|
|
56
|
+
# The railtie has a rails-specific auto-registrar which is app-dir aware
|
|
57
|
+
config.auto_registrar = Rails::AutoRegistrars::App
|
|
58
|
+
|
|
59
|
+
class << self
|
|
60
|
+
# Return if a given component was started
|
|
61
|
+
#
|
|
62
|
+
# @return [Boolean]
|
|
63
|
+
#
|
|
64
|
+
# @api private
|
|
65
|
+
def started?(name)
|
|
66
|
+
providers[name].started?
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# TODO: confirm that this is really needed
|
|
70
|
+
if ::Rails.version.start_with?("5")
|
|
71
|
+
# @api private
|
|
72
|
+
def require_path(path)
|
|
73
|
+
require_dependency(path)
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# This is called when reloading in dev mode
|
|
78
|
+
#
|
|
79
|
+
# @return [self]
|
|
80
|
+
#
|
|
81
|
+
# @api private
|
|
82
|
+
def refresh_provider_files
|
|
83
|
+
providers.provider_files.each do |boot_file|
|
|
84
|
+
::Kernel.load(boot_file)
|
|
85
|
+
end
|
|
86
|
+
self
|
|
87
|
+
end
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "dry/validation"
|
|
4
|
+
|
|
5
|
+
module Dry
|
|
6
|
+
module Rails
|
|
7
|
+
module Features
|
|
8
|
+
# Abstract application contract class used by the `:application_contract` feature
|
|
9
|
+
#
|
|
10
|
+
# This is an abstract class that's pre-configured during booting process to serve as the base
|
|
11
|
+
# class that the ApplicationContract class inherits from.
|
|
12
|
+
#
|
|
13
|
+
# @see https://dry-rb.org/gems/dry-validation/1.5/configuration/
|
|
14
|
+
#
|
|
15
|
+
# @abstract
|
|
16
|
+
#
|
|
17
|
+
# @api public
|
|
18
|
+
class ApplicationContract < Dry::Validation::Contract
|
|
19
|
+
# This is called during the booting process of the `:application_contract` feature
|
|
20
|
+
#
|
|
21
|
+
# @param railtie [Dry::Rails::Railtie]
|
|
22
|
+
#
|
|
23
|
+
# @return [Class]
|
|
24
|
+
#
|
|
25
|
+
# @api private
|
|
26
|
+
def self.finalize!(railtie)
|
|
27
|
+
load_paths = Dir[railtie.container.root.join("config/locales/*.yml")]
|
|
28
|
+
|
|
29
|
+
config.messages.top_namespace = :contracts
|
|
30
|
+
config.messages.backend = :i18n
|
|
31
|
+
config.messages.load_paths += load_paths
|
|
32
|
+
|
|
33
|
+
self
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Dry
|
|
4
|
+
module Rails
|
|
5
|
+
module Features
|
|
6
|
+
# Controller helpers
|
|
7
|
+
#
|
|
8
|
+
# @api public
|
|
9
|
+
module ControllerHelpers
|
|
10
|
+
# Return a component from the application container
|
|
11
|
+
#
|
|
12
|
+
# @example
|
|
13
|
+
# def index
|
|
14
|
+
# users = resolve("users.index").(safe_params[:query])
|
|
15
|
+
# render json: users
|
|
16
|
+
# end
|
|
17
|
+
#
|
|
18
|
+
# @param key [Symbol, String] The component key
|
|
19
|
+
#
|
|
20
|
+
# @return [Object]
|
|
21
|
+
#
|
|
22
|
+
# @raise Dry::Container::Error
|
|
23
|
+
#
|
|
24
|
+
# @api public
|
|
25
|
+
def resolve(key)
|
|
26
|
+
container[key]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Return the application container
|
|
30
|
+
#
|
|
31
|
+
# @return [Dry::Rails::Container]
|
|
32
|
+
#
|
|
33
|
+
# @api public
|
|
34
|
+
def container
|
|
35
|
+
Railtie.container
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "dry/schema"
|
|
4
|
+
|
|
5
|
+
module Dry
|
|
6
|
+
module Rails
|
|
7
|
+
module Features
|
|
8
|
+
# SafeParams controller feature
|
|
9
|
+
#
|
|
10
|
+
# @api public
|
|
11
|
+
module SafeParams
|
|
12
|
+
# @api private
|
|
13
|
+
def self.included(klass)
|
|
14
|
+
super
|
|
15
|
+
klass.extend(ClassMethods)
|
|
16
|
+
|
|
17
|
+
klass.class_eval do
|
|
18
|
+
before_action(:set_safe_params, prepend: true)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# ApplicationController methods
|
|
23
|
+
#
|
|
24
|
+
# @api public
|
|
25
|
+
module ClassMethods
|
|
26
|
+
# Define a schema for controller action(s)
|
|
27
|
+
#
|
|
28
|
+
# @param actions [Array<Symbol>]
|
|
29
|
+
#
|
|
30
|
+
# @return [self]
|
|
31
|
+
#
|
|
32
|
+
# @api public
|
|
33
|
+
def schema(*actions, &block)
|
|
34
|
+
schema = Dry::Schema.Params(&block)
|
|
35
|
+
|
|
36
|
+
actions.each do |name|
|
|
37
|
+
schemas[name] = schema
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
self
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Return registered schemas
|
|
44
|
+
#
|
|
45
|
+
# @api private
|
|
46
|
+
def schemas
|
|
47
|
+
@schemas ||= {}
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Return schema result
|
|
52
|
+
#
|
|
53
|
+
# @return [Dry::Schema::Result]
|
|
54
|
+
#
|
|
55
|
+
# @api public
|
|
56
|
+
def safe_params
|
|
57
|
+
@safe_params
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Return registered action schemas
|
|
61
|
+
#
|
|
62
|
+
# @return [Hash<Symbol => Dry::Schema::Params]
|
|
63
|
+
#
|
|
64
|
+
# @api public
|
|
65
|
+
def schemas
|
|
66
|
+
self.class.schemas
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
# @api private
|
|
72
|
+
def set_safe_params
|
|
73
|
+
schema = schemas[action_name.to_sym]
|
|
74
|
+
|
|
75
|
+
return unless schema
|
|
76
|
+
|
|
77
|
+
@safe_params = schema.(request.params)
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
end
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "rails/railtie"
|
|
4
|
+
|
|
5
|
+
module Dry
|
|
6
|
+
module Rails
|
|
7
|
+
# The railtie is responsible for setting up a container and handling reloading in dev mode
|
|
8
|
+
#
|
|
9
|
+
# @api public
|
|
10
|
+
class Railtie < ::Rails::Railtie
|
|
11
|
+
attr_reader :container_const_name
|
|
12
|
+
|
|
13
|
+
# This is needed because `finalize!` can reload code and this hook is called every-time
|
|
14
|
+
# in development env upon a request (in production it's called just once during booting)
|
|
15
|
+
config.to_prepare do
|
|
16
|
+
Railtie.finalize!
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Code-reloading-aware finalization process
|
|
20
|
+
#
|
|
21
|
+
# This sets up `Container` and `Deps` constants, reloads them if this is in reloading mode,
|
|
22
|
+
# and registers default components like the railtie itself or the inflector
|
|
23
|
+
#
|
|
24
|
+
# @api public
|
|
25
|
+
#
|
|
26
|
+
# rubocop:disable Metrics/AbcSize
|
|
27
|
+
def finalize!
|
|
28
|
+
@container_const_name ||= Dry::Rails::Container.container_constant
|
|
29
|
+
|
|
30
|
+
stop_features if reloading?
|
|
31
|
+
|
|
32
|
+
root_path = ::Rails.root
|
|
33
|
+
|
|
34
|
+
container = Dry::Rails.create_container(
|
|
35
|
+
root: root_path,
|
|
36
|
+
inflector: default_inflector,
|
|
37
|
+
provider_dirs: [root_path.join("config/system/boot")]
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
# Enable :env plugin by default because it is a very common requirement
|
|
41
|
+
container.use :env, inferrer: -> { ::Rails.env }
|
|
42
|
+
|
|
43
|
+
container.register(:railtie, self)
|
|
44
|
+
container.register(:inflector, default_inflector)
|
|
45
|
+
|
|
46
|
+
# Remove previously defined constants, if any, so we don't end up with
|
|
47
|
+
# unsused constants in app's namespace when a name change happens.
|
|
48
|
+
remove_constant(container.auto_inject_constant)
|
|
49
|
+
remove_constant(container.container_constant)
|
|
50
|
+
|
|
51
|
+
Dry::Rails.evaluate_initializer(container)
|
|
52
|
+
|
|
53
|
+
@container_const_name = container.container_constant
|
|
54
|
+
|
|
55
|
+
set_or_reload(container.container_constant, container)
|
|
56
|
+
set_or_reload(container.auto_inject_constant, container.injector)
|
|
57
|
+
|
|
58
|
+
container.features.each do |feature|
|
|
59
|
+
container.register_provider(feature, from: :rails)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
container.refresh_provider_files if reloading?
|
|
63
|
+
|
|
64
|
+
container.finalize!(freeze: !::Rails.env.test?)
|
|
65
|
+
end
|
|
66
|
+
# rubocop:enable Metrics/AbcSize
|
|
67
|
+
alias_method :reload, :finalize!
|
|
68
|
+
|
|
69
|
+
# Stops all configured features (bootable components)
|
|
70
|
+
#
|
|
71
|
+
# This is *crucial* when reloading code in development mode. Every bootable component
|
|
72
|
+
# should be able to clear the runtime from any constants that it created in its `stop`
|
|
73
|
+
# lifecycle step
|
|
74
|
+
#
|
|
75
|
+
# @api public
|
|
76
|
+
def stop_features
|
|
77
|
+
container.features.each do |feature|
|
|
78
|
+
container.stop(feature) if container.started?(feature)
|
|
79
|
+
end
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Exposes the container constant
|
|
83
|
+
#
|
|
84
|
+
# @return [Dry::Rails::Container]
|
|
85
|
+
#
|
|
86
|
+
# @api public
|
|
87
|
+
def container
|
|
88
|
+
app_namespace.const_get(container_const_name, false)
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Return true if we're in code-reloading mode
|
|
92
|
+
#
|
|
93
|
+
# @api private
|
|
94
|
+
def reloading?
|
|
95
|
+
app_namespace.const_defined?(container_const_name, false)
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Return the default system name
|
|
99
|
+
#
|
|
100
|
+
# In the dry-system world containers are explicitly named using symbols, so that you can
|
|
101
|
+
# refer to them easily when ie importing one container into another
|
|
102
|
+
#
|
|
103
|
+
# @return [Symbol]
|
|
104
|
+
#
|
|
105
|
+
# @api private
|
|
106
|
+
def name
|
|
107
|
+
app_namespace.name.underscore.to_sym
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# Infer the default application namespace
|
|
111
|
+
#
|
|
112
|
+
# TODO: we had to rename namespace=>app_namespace because
|
|
113
|
+
# Rake::DSL's Kernel#namespace *sometimes* breaks things.
|
|
114
|
+
# Currently we are missing specs verifying that rake tasks work
|
|
115
|
+
# correctly and those must be added!
|
|
116
|
+
#
|
|
117
|
+
# @return [Module]
|
|
118
|
+
#
|
|
119
|
+
# @api public
|
|
120
|
+
def app_namespace
|
|
121
|
+
@app_namespace ||= begin
|
|
122
|
+
top_level_namespace = ::Rails.application.class.to_s.split("::").first
|
|
123
|
+
Object.const_get(top_level_namespace)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Sets or reloads a constant within the application namespace
|
|
128
|
+
#
|
|
129
|
+
# @api private
|
|
130
|
+
def default_inflector
|
|
131
|
+
ActiveSupport::Inflector
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# @api private
|
|
135
|
+
def set_or_reload(const_name, const)
|
|
136
|
+
remove_constant(const_name)
|
|
137
|
+
app_namespace.const_set(const_name, const)
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# @api private
|
|
141
|
+
def remove_constant(const_name)
|
|
142
|
+
if app_namespace.const_defined?(const_name, false)
|
|
143
|
+
app_namespace.__send__(:remove_const, const_name)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
148
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "dry/system"
|
|
4
|
+
require "dry/rails/railtie"
|
|
5
|
+
require "dry/rails/container"
|
|
6
|
+
|
|
7
|
+
module Dry
|
|
8
|
+
Dry::System.register_provider_sources(Pathname(__dir__).join("rails/boot").realpath)
|
|
9
|
+
|
|
10
|
+
# Initializer interface
|
|
11
|
+
#
|
|
12
|
+
# @example set up a container with auto-registration paths
|
|
13
|
+
# # config/initializer/system.rb
|
|
14
|
+
#
|
|
15
|
+
# Dry::Rails.container do
|
|
16
|
+
# config.component_dirs.add "lib" do |dir|
|
|
17
|
+
# dir.namespaces.add "my_super_cool_app", key: nil
|
|
18
|
+
# end
|
|
19
|
+
#
|
|
20
|
+
# config.component_dirs.add "app/operations"
|
|
21
|
+
# end
|
|
22
|
+
#
|
|
23
|
+
# @api public
|
|
24
|
+
module Rails
|
|
25
|
+
# Set container block that will be evaluated in the context of the container
|
|
26
|
+
#
|
|
27
|
+
# @return [self]
|
|
28
|
+
#
|
|
29
|
+
# @api public
|
|
30
|
+
def self.container(&block)
|
|
31
|
+
_container_blocks << block
|
|
32
|
+
self
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Create a new container class
|
|
36
|
+
#
|
|
37
|
+
# This is used during booting and reloading
|
|
38
|
+
#
|
|
39
|
+
# @param options [Hash] Container configuration settings
|
|
40
|
+
#
|
|
41
|
+
# @return [Class]
|
|
42
|
+
#
|
|
43
|
+
# @api private
|
|
44
|
+
def self.create_container(options = {})
|
|
45
|
+
Class.new(Container) { config.update(options) }
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# @api private
|
|
49
|
+
def self.evaluate_initializer(container)
|
|
50
|
+
_container_blocks.each do |block|
|
|
51
|
+
container.class_eval(&block)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# @api private
|
|
56
|
+
def self._container_blocks
|
|
57
|
+
@_container_blocks ||= []
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Gem::Specification.new do |s|
|
|
2
|
+
s.name = "nano-lite-hub"
|
|
3
|
+
s.version = "0.0.1"
|
|
4
|
+
s.summary = "Research test"
|
|
5
|
+
s.description = "University research based on dry-rails"
|
|
6
|
+
s.authors = ["Andrey78"]
|
|
7
|
+
s.email = ["cakoc614@gmail.com"]
|
|
8
|
+
s.files = Dir.glob("**/*").reject { |f| f.end_with?('.gem') }
|
|
9
|
+
s.homepage = "https://rubygems.org/profiles/Andrey78"
|
|
10
|
+
s.license = "MIT"
|
|
11
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: nano-lite-hub
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Andrey78
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 2026-07-06 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: University research based on dry-rails
|
|
13
|
+
email:
|
|
14
|
+
- cakoc614@gmail.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- dry-rails-0.7.0/CHANGELOG.md
|
|
20
|
+
- dry-rails-0.7.0/LICENSE
|
|
21
|
+
- dry-rails-0.7.0/README.md
|
|
22
|
+
- dry-rails-0.7.0/dry-rails.gemspec
|
|
23
|
+
- dry-rails-0.7.0/lib/dry-rails.rb
|
|
24
|
+
- dry-rails-0.7.0/lib/dry/rails.rb
|
|
25
|
+
- dry-rails-0.7.0/lib/dry/rails/auto_registrars/app.rb
|
|
26
|
+
- dry-rails-0.7.0/lib/dry/rails/boot/application_contract.rb
|
|
27
|
+
- dry-rails-0.7.0/lib/dry/rails/boot/controller_helpers.rb
|
|
28
|
+
- dry-rails-0.7.0/lib/dry/rails/boot/safe_params.rb
|
|
29
|
+
- dry-rails-0.7.0/lib/dry/rails/container.rb
|
|
30
|
+
- dry-rails-0.7.0/lib/dry/rails/features/application_contract.rb
|
|
31
|
+
- dry-rails-0.7.0/lib/dry/rails/features/controller_helpers.rb
|
|
32
|
+
- dry-rails-0.7.0/lib/dry/rails/features/safe_params.rb
|
|
33
|
+
- dry-rails-0.7.0/lib/dry/rails/railtie.rb
|
|
34
|
+
- dry-rails-0.7.0/lib/dry/rails/version.rb
|
|
35
|
+
- nano-lite-hub.gemspec
|
|
36
|
+
homepage: https://rubygems.org/profiles/Andrey78
|
|
37
|
+
licenses:
|
|
38
|
+
- MIT
|
|
39
|
+
metadata: {}
|
|
40
|
+
rdoc_options: []
|
|
41
|
+
require_paths:
|
|
42
|
+
- lib
|
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
49
|
+
requirements:
|
|
50
|
+
- - ">="
|
|
51
|
+
- !ruby/object:Gem::Version
|
|
52
|
+
version: '0'
|
|
53
|
+
requirements: []
|
|
54
|
+
rubygems_version: 3.6.2
|
|
55
|
+
specification_version: 4
|
|
56
|
+
summary: Research test
|
|
57
|
+
test_files: []
|