hanami 2.2.1 → 2.3.0.beta2
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 +4 -4
- data/CHANGELOG.md +49 -1
- data/README.md +20 -35
- data/hanami.gemspec +9 -8
- data/lib/hanami/app.rb +2 -0
- data/lib/hanami/config/actions/content_security_policy.rb +23 -0
- data/lib/hanami/config/actions.rb +21 -0
- data/lib/hanami/config/console.rb +79 -0
- data/lib/hanami/config/logger.rb +1 -1
- data/lib/hanami/config.rb +14 -1
- data/lib/hanami/constants.rb +3 -0
- data/lib/hanami/extensions/db/repo.rb +11 -6
- data/lib/hanami/extensions/view/context.rb +10 -10
- data/lib/hanami/extensions/view/slice_configured_context.rb +0 -7
- data/lib/hanami/helpers/assets_helper.rb +92 -25
- data/lib/hanami/middleware/content_security_policy_nonce.rb +53 -0
- data/lib/hanami/routes.rb +3 -3
- data/lib/hanami/slice.rb +34 -6
- data/lib/hanami/slice_registrar.rb +1 -1
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami.rb +10 -2
- data/spec/integration/action/format_config_spec.rb +6 -3
- data/spec/integration/action/slice_configuration_spec.rb +36 -36
- data/spec/integration/assets/cross_slice_assets_helpers_spec.rb +0 -1
- data/spec/integration/assets/serve_static_assets_spec.rb +1 -1
- data/spec/integration/container/autoloader_spec.rb +2 -0
- data/spec/integration/db/db_spec.rb +1 -1
- data/spec/integration/db/logging_spec.rb +63 -0
- data/spec/integration/db/repo_spec.rb +87 -2
- data/spec/integration/logging/exception_logging_spec.rb +6 -1
- data/spec/integration/rack_app/body_parser_spec.rb +2 -1
- data/spec/integration/rack_app/middleware_spec.rb +4 -11
- data/spec/integration/rack_app/rack_app_spec.rb +2 -2
- data/spec/integration/view/helpers/form_helper_spec.rb +1 -1
- data/spec/integration/web/content_security_policy_nonce_spec.rb +251 -0
- data/spec/support/app_integration.rb +2 -1
- data/spec/unit/hanami/config/actions/content_security_policy_spec.rb +7 -0
- data/spec/unit/hanami/config/actions_spec.rb +2 -2
- data/spec/unit/hanami/config/console_spec.rb +22 -0
- data/spec/unit/hanami/env_spec.rb +10 -13
- data/spec/unit/hanami/slice_spec.rb +18 -0
- data/spec/unit/hanami/web/rack_logger_spec.rb +11 -4
- metadata +34 -29
- data/spec/integration/view/context/settings_spec.rb +0 -46
- data/spec/support/shared_examples/cli/generate/app.rb +0 -494
- data/spec/support/shared_examples/cli/generate/migration.rb +0 -32
- data/spec/support/shared_examples/cli/generate/model.rb +0 -81
- data/spec/support/shared_examples/cli/new.rb +0 -97
- data/spec/unit/hanami/version_spec.rb +0 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: d2b1e7bd746a82ee41c5240dff465f74f79c783ebd9ed73c21b41144dff2a641
|
|
4
|
+
data.tar.gz: d0b26e86ba4736cdd2841abf353ad58d3064f381a6e45adb615c4d8c28ca7c95
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 35f0d90cf493960b018734f68aa210b362195d1efbca45308efa8c877f9ec6220b37a1cd8a753034d3a4e27a623de7d40bd8d02b0786b140b5dd0fda631de246
|
|
7
|
+
data.tar.gz: 735d731e95a0edc4858e8d1930e10540664f25ed3f9069bda184570e9056800f83cc6f2b3ac0703e45e261d33e163e9cb55c80c76b1dc95be074901b691a261a
|
data/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
1
|
# Hanami
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## [Unreleased]
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
### Changed
|
|
8
|
+
|
|
9
|
+
### Deprecated
|
|
10
|
+
|
|
11
|
+
### Removed
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
|
|
15
|
+
### Security
|
|
16
|
+
|
|
17
|
+
## [v2.3.0.beta1] - 2025-10-17
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Use updated API for `config.actions.formats`. (@timriley in #1544)
|
|
22
|
+
- Show relative paths in `MissingActionError`. (@kyleplump and @timriley in #1445)
|
|
23
|
+
|
|
24
|
+
### Removed
|
|
25
|
+
|
|
26
|
+
- View context `settings` has been removed and is no longer accessible from templates. (@baweaver in #1536)
|
|
27
|
+
|
|
28
|
+
## [v2.3.0.beta1] - 2025-10-03
|
|
29
|
+
|
|
30
|
+
### Added
|
|
31
|
+
|
|
32
|
+
- Add `config.console` settings to app. Set an alternative engine with e.g. `config.console.engine = :pry` (`:irb` is default). Add your own methods to the console with `config.console.include MyModule, AnotherModule`. (@alassek in #1540)
|
|
33
|
+
- Support optional nonce in Rack requests, CSP header rules and view helpers (@svoop in #1500)
|
|
34
|
+
- Check `ENV["APP_ENV"]` for the Hanami env if `ENV["HANAMI_ENV"]` is not set. The order of environment variable checks is now `HANAMI_ENV`->`APP_ENV`->`RACK_ENV` (@svoop in #1487).
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
|
|
38
|
+
- Support both Rack v2 and v3. (@kyleplump in #1493)
|
|
39
|
+
- Support single-character slice names. (@aaronmallen in #1528)
|
|
40
|
+
|
|
41
|
+
### Fixed
|
|
42
|
+
|
|
43
|
+
- Allow `include Deps` to be used in `Hanami::DB::Repo` subclasses. (@wuarmin in #1523)
|
|
44
|
+
- Properly infer root relations for deeper `Hanami::DB::Repo` subclasses, such as in slices. (@wuarmin in #1478)
|
|
45
|
+
- Delay loading `config/routes.rb` until after autoloading is setup, which means you can access your constants there. (@timriley in #1539)
|
|
46
|
+
- Avoid warning from referencing deprecated `URI::DEFAULT_PARSER`. (@wuarmin in #1518)
|
|
4
47
|
|
|
5
48
|
## v2.2.1 - 2024-11-12
|
|
6
49
|
|
|
@@ -1478,3 +1521,8 @@ end
|
|
|
1478
1521
|
- [Luca Guidi] Introduced `Lotus::Configuration`
|
|
1479
1522
|
- [Luca Guidi] Introduced `Lotus::Application`
|
|
1480
1523
|
- [Luca Guidi] Official support for MRI 2.0
|
|
1524
|
+
|
|
1525
|
+
|
|
1526
|
+
[unreleased]: https://github.com/hanami/hanami/compare/v2.3.0.beta2...HEAD
|
|
1527
|
+
[v2.3.0.beta2] https://github.com/hanami/hanami/compare/v2.3.0.beta1...v2.3.0.beta2
|
|
1528
|
+
[v2.3.0.beta1] https://github.com/hanami/hanami/compare/v2.2.1...v2.3.0.beta1
|
data/README.md
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
1
|
# Hanami :cherry_blossom:
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
## Version
|
|
6
|
-
|
|
7
|
-
**This branch contains the code for `hanami`: 2.2**
|
|
8
|
-
|
|
9
|
-
## Frameworks
|
|
3
|
+
**A flexible framework for maintainable Ruby apps.**
|
|
10
4
|
|
|
11
5
|
Hanami is a **full-stack** Ruby web framework. It's made up of smaller, single-purpose libraries.
|
|
12
6
|
|
|
@@ -14,8 +8,8 @@ This repository is for the full-stack framework, which provides the glue that ti
|
|
|
14
8
|
|
|
15
9
|
* [**Hanami::Router**](https://github.com/hanami/router) - Rack compatible HTTP router for Ruby
|
|
16
10
|
* [**Hanami::Controller**](https://github.com/hanami/controller) - Full featured, fast and testable actions for Rack
|
|
17
|
-
* [**Hanami::Validations**](https://github.com/hanami/validations) - Parameter validations & coercion for actions
|
|
18
11
|
* [**Hanami::View**](https://github.com/hanami/view) - Presentation with a separation between views and templates
|
|
12
|
+
* [**Hanami::DB**](https://github.com/hanami/db) - Database integration, complete with migrations, repositories, relations, and structs
|
|
19
13
|
* [**Hanami::Assets**](https://github.com/hanami/assets) - Assets management for Ruby
|
|
20
14
|
|
|
21
15
|
These components are designed to be used independently or together in a Hanami application.
|
|
@@ -24,12 +18,10 @@ These components are designed to be used independently or together in a Hanami a
|
|
|
24
18
|
|
|
25
19
|
[](https://badge.fury.io/rb/hanami)
|
|
26
20
|
[](https://github.com/hanami/hanami/actions?query=workflow%3Aci+branch%3Amain)
|
|
27
|
-
[](https://codecov.io/gh/hanami/hanami)
|
|
28
|
-
[](https://depfu.com/github/hanami/hanami?project=Bundler)
|
|
29
21
|
|
|
30
22
|
## Installation
|
|
31
23
|
|
|
32
|
-
|
|
24
|
+
Hanami supports Ruby (MRI) 3.1+.
|
|
33
25
|
|
|
34
26
|
```shell
|
|
35
27
|
gem install hanami
|
|
@@ -40,7 +32,8 @@ gem install hanami
|
|
|
40
32
|
```shell
|
|
41
33
|
hanami new bookshelf
|
|
42
34
|
cd bookshelf && bundle
|
|
43
|
-
bundle exec hanami
|
|
35
|
+
bundle exec hanami dev
|
|
36
|
+
# Now visit http://localhost:2300
|
|
44
37
|
```
|
|
45
38
|
|
|
46
39
|
Please follow along with the [Getting Started guide](https://guides.hanamirb.org/getting-started/).
|
|
@@ -49,30 +42,22 @@ Please follow along with the [Getting Started guide](https://guides.hanamirb.org
|
|
|
49
42
|
|
|
50
43
|
You can give back to Open Source, by supporting Hanami development via [GitHub Sponsors](https://github.com/sponsors/hanami).
|
|
51
44
|
|
|
52
|
-
### Supporters
|
|
53
|
-
|
|
54
|
-
* [Trung Lê](https://github.com/runlevel5)
|
|
55
|
-
* [James Carlson](https://github.com/jxxcarlson)
|
|
56
|
-
* [Creditas](https://www.creditas.com.br/)
|
|
57
|
-
|
|
58
45
|
## Contact
|
|
59
46
|
|
|
60
|
-
* Home page
|
|
61
|
-
* Community
|
|
62
|
-
* Guides
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* Bugs/Issues: https://github.com/hanami/hanami/issues
|
|
67
|
-
* Stack Overflow: http://stackoverflow.com/questions/tagged/hanami
|
|
68
|
-
* Forum: https://discourse.hanamirb.org
|
|
69
|
-
* **Chat**: http://chat.hanamirb.org
|
|
47
|
+
* [Home page](http://hanamirb.org)
|
|
48
|
+
* [Community](http://hanamirb.org/community)
|
|
49
|
+
* [Guides](https://guides.hanamirb.org)
|
|
50
|
+
* [Issues](https://github.com/hanami/hanami/issues)
|
|
51
|
+
* [Forum](https://discourse.hanamirb.org)
|
|
52
|
+
* [Chat](https://discord.gg/KFCxDmk3JQ)
|
|
70
53
|
|
|
71
54
|
## Community
|
|
72
55
|
|
|
73
|
-
We
|
|
56
|
+
We care about building a friendly, inclusive and helpful community. We welcome people of all backgrounds, genders and experience levels, and respect you all equally.
|
|
57
|
+
|
|
58
|
+
We do not tolerate nazis, transphobes, racists, or any kind of bigotry. See our [code of conduct](http://hanamirb.org/community/#code-of-conduct) for more.
|
|
74
59
|
|
|
75
|
-
## Contributing
|
|
60
|
+
## Contributing
|
|
76
61
|
|
|
77
62
|
1. Fork it ( https://github.com/hanami/hanami/fork )
|
|
78
63
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
@@ -110,14 +95,14 @@ $ bundle exec rspec path/to/spec.rb
|
|
|
110
95
|
|
|
111
96
|
### Development Requirements
|
|
112
97
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
98
|
+
* Ruby >= 3.1
|
|
99
|
+
* Bundler
|
|
100
|
+
* Node.js
|
|
116
101
|
|
|
117
102
|
## Versioning
|
|
118
103
|
|
|
119
|
-
|
|
104
|
+
Hanami uses [Semantic Versioning 2.0.0](http://semver.org).
|
|
120
105
|
|
|
121
106
|
## Copyright
|
|
122
107
|
|
|
123
|
-
Copyright © 2014–
|
|
108
|
+
Copyright © 2014–2025 Hanami Team – Released under MIT License.
|
data/hanami.gemspec
CHANGED
|
@@ -7,10 +7,10 @@ require "hanami/version"
|
|
|
7
7
|
Gem::Specification.new do |spec|
|
|
8
8
|
spec.name = "hanami"
|
|
9
9
|
spec.version = Hanami::VERSION
|
|
10
|
-
spec.authors = ["
|
|
11
|
-
spec.email = ["
|
|
12
|
-
spec.summary = "
|
|
13
|
-
spec.description =
|
|
10
|
+
spec.authors = ["Hanakai team"]
|
|
11
|
+
spec.email = ["info@hanakai.org"]
|
|
12
|
+
spec.summary = "A flexible framework for maintainable Ruby apps"
|
|
13
|
+
spec.description = spec.summary
|
|
14
14
|
spec.homepage = "http://hanamirb.org"
|
|
15
15
|
spec.license = "MIT"
|
|
16
16
|
|
|
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
|
|
|
27
27
|
spec.test_files = Dir["spec/**/*"]
|
|
28
28
|
spec.require_paths = ["lib"]
|
|
29
29
|
spec.metadata["rubygems_mfa_required"] = "true"
|
|
30
|
-
spec.required_ruby_version = ">= 3.
|
|
30
|
+
spec.required_ruby_version = ">= 3.2"
|
|
31
31
|
|
|
32
32
|
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
33
33
|
|
|
@@ -38,12 +38,13 @@ Gem::Specification.new do |spec|
|
|
|
38
38
|
spec.add_dependency "dry-monitor", "~> 1.0", ">= 1.0.1", "< 2"
|
|
39
39
|
spec.add_dependency "dry-system", "~> 1.1"
|
|
40
40
|
spec.add_dependency "dry-logger", "~> 1.0", "< 2"
|
|
41
|
-
spec.add_dependency "hanami-cli", "~> 2.
|
|
42
|
-
spec.add_dependency "hanami-utils", "~> 2.
|
|
41
|
+
spec.add_dependency "hanami-cli", "~> 2.3.0.beta2"
|
|
42
|
+
spec.add_dependency "hanami-utils", "~> 2.3.0.beta2"
|
|
43
43
|
spec.add_dependency "json", ">= 2.7.2"
|
|
44
44
|
spec.add_dependency "zeitwerk", "~> 2.6"
|
|
45
|
+
spec.add_dependency "rack-session"
|
|
45
46
|
|
|
46
47
|
spec.add_development_dependency "rspec", "~> 3.8"
|
|
47
|
-
spec.add_development_dependency "rack-test", "~>
|
|
48
|
+
spec.add_development_dependency "rack-test", "~> 2.0"
|
|
48
49
|
spec.add_development_dependency "rake", "~> 13.0"
|
|
49
50
|
end
|
data/lib/hanami/app.rb
CHANGED
|
@@ -168,6 +168,8 @@ module Hanami
|
|
|
168
168
|
end
|
|
169
169
|
|
|
170
170
|
def prepare_autoloader
|
|
171
|
+
autoloader.tag = "hanami.app.#{slice_name.name}"
|
|
172
|
+
|
|
171
173
|
# Component dirs are automatically pushed to the autoloader by dry-system's zeitwerk plugin.
|
|
172
174
|
# This method adds other dirs that are not otherwise configured as component dirs.
|
|
173
175
|
|
|
@@ -96,6 +96,29 @@ module Hanami
|
|
|
96
96
|
@policy.delete(key)
|
|
97
97
|
end
|
|
98
98
|
|
|
99
|
+
# Returns true if 'nonce' is used in any of the policies.
|
|
100
|
+
#
|
|
101
|
+
# @return [Boolean]
|
|
102
|
+
#
|
|
103
|
+
# @api public
|
|
104
|
+
# @since x.x.x
|
|
105
|
+
def nonce?
|
|
106
|
+
@policy.any? { _2.match?(/'nonce'/) }
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# Returns an array of middleware name to support 'nonce' in
|
|
110
|
+
# policies, or an empty array if 'nonce' is not used.
|
|
111
|
+
#
|
|
112
|
+
# @return [Array<(Symbol, Array)>]
|
|
113
|
+
#
|
|
114
|
+
# @api public
|
|
115
|
+
# @since x.x.x
|
|
116
|
+
def middleware
|
|
117
|
+
return [] unless nonce?
|
|
118
|
+
|
|
119
|
+
[Hanami::Middleware::ContentSecurityPolicyNonce]
|
|
120
|
+
end
|
|
121
|
+
|
|
99
122
|
# @since 2.0.0
|
|
100
123
|
# @api private
|
|
101
124
|
def to_s
|
|
@@ -74,6 +74,23 @@ module Hanami
|
|
|
74
74
|
# @since 2.0.0
|
|
75
75
|
attr_accessor :content_security_policy
|
|
76
76
|
|
|
77
|
+
# Returns the proc to generate Content Security Policy nonce values.
|
|
78
|
+
#
|
|
79
|
+
# The current Rack request object is provided as an optional argument
|
|
80
|
+
# to the proc, enabling the generation of nonces based on session IDs.
|
|
81
|
+
#
|
|
82
|
+
# @example Independent random nonce (default)
|
|
83
|
+
# -> { SecureRandom.urlsafe_base64(16) }
|
|
84
|
+
#
|
|
85
|
+
# @example Session dependent nonce
|
|
86
|
+
# ->(request) { Digest::SHA256.base64digest(request.session[:uuid])[0, 16] }
|
|
87
|
+
#
|
|
88
|
+
# @return [Proc]
|
|
89
|
+
#
|
|
90
|
+
# @api public
|
|
91
|
+
# @since x.x.x
|
|
92
|
+
setting :content_security_policy_nonce_generator, default: -> { SecureRandom.urlsafe_base64(16) }
|
|
93
|
+
|
|
77
94
|
# @!attribute [rw] method_override
|
|
78
95
|
# Sets or returns whether HTTP method override should be enabled for action classes.
|
|
79
96
|
#
|
|
@@ -138,6 +155,10 @@ module Hanami
|
|
|
138
155
|
end
|
|
139
156
|
end
|
|
140
157
|
|
|
158
|
+
# @api public
|
|
159
|
+
# @since x.x.x
|
|
160
|
+
def content_security_policy? = !!@content_security_policy
|
|
161
|
+
|
|
141
162
|
private
|
|
142
163
|
|
|
143
164
|
# Apply defaults for base config
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "dry/configurable"
|
|
4
|
+
|
|
5
|
+
module Hanami
|
|
6
|
+
class Config
|
|
7
|
+
# Hanami console config
|
|
8
|
+
#
|
|
9
|
+
# @since 2.3.0
|
|
10
|
+
# @api public
|
|
11
|
+
class Console
|
|
12
|
+
include Dry::Configurable
|
|
13
|
+
|
|
14
|
+
# @!attribute [rw] engine
|
|
15
|
+
# Sets or returns the interactive console engine to be used by `hanami console`.
|
|
16
|
+
# Supported values are `:irb` (default) and `:pry`.
|
|
17
|
+
#
|
|
18
|
+
# @example
|
|
19
|
+
# config.console.engine = :pry
|
|
20
|
+
#
|
|
21
|
+
# @return [Symbol]
|
|
22
|
+
#
|
|
23
|
+
# @api public
|
|
24
|
+
# @since 2.3.0
|
|
25
|
+
setting :engine, default: :irb
|
|
26
|
+
|
|
27
|
+
# Returns the complete list of extensions to be used in the console
|
|
28
|
+
#
|
|
29
|
+
# @example
|
|
30
|
+
# config.console.include MyExtension, OtherExtension
|
|
31
|
+
# config.console.include ThirdExtension
|
|
32
|
+
#
|
|
33
|
+
# config.console.extensions
|
|
34
|
+
# # => [MyExtension, OtherExtension, ThirdExtension]
|
|
35
|
+
#
|
|
36
|
+
# @return [Array<Module>]
|
|
37
|
+
#
|
|
38
|
+
# @api public
|
|
39
|
+
# @since 2.3.0
|
|
40
|
+
def extensions = @extensions.dup.freeze
|
|
41
|
+
|
|
42
|
+
# Define a module extension to be included in the console
|
|
43
|
+
#
|
|
44
|
+
# @param mod [Module] one or more modules to be included in the console
|
|
45
|
+
# @return [void]
|
|
46
|
+
#
|
|
47
|
+
# @api public
|
|
48
|
+
# @since 2.3.0
|
|
49
|
+
def include(*mod)
|
|
50
|
+
@extensions.concat(mod).uniq!
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# @api private
|
|
54
|
+
def initialize
|
|
55
|
+
@extensions = []
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
private
|
|
59
|
+
|
|
60
|
+
# @api private
|
|
61
|
+
def initialize_copy(source)
|
|
62
|
+
super
|
|
63
|
+
@extensions = [*source.extensions]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def method_missing(name, *args, &block)
|
|
67
|
+
if config.respond_to?(name)
|
|
68
|
+
config.public_send(name, *args, &block)
|
|
69
|
+
else
|
|
70
|
+
super
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def respond_to_missing?(name, _include_all = false)
|
|
75
|
+
config.respond_to?(name) || super
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
end
|
data/lib/hanami/config/logger.rb
CHANGED
data/lib/hanami/config.rb
CHANGED
|
@@ -6,6 +6,7 @@ require "dry/configurable"
|
|
|
6
6
|
require "dry/inflector"
|
|
7
7
|
|
|
8
8
|
require_relative "constants"
|
|
9
|
+
require_relative "config/console"
|
|
9
10
|
|
|
10
11
|
module Hanami
|
|
11
12
|
# Hanami app config
|
|
@@ -184,6 +185,18 @@ module Hanami
|
|
|
184
185
|
"Hanami::Router::NotFoundError" => :not_found,
|
|
185
186
|
)
|
|
186
187
|
|
|
188
|
+
# @!attribute [rw] console
|
|
189
|
+
# Returns the app's console config
|
|
190
|
+
#
|
|
191
|
+
# @example
|
|
192
|
+
# config.console.engine # => :irb
|
|
193
|
+
#
|
|
194
|
+
# @return [Hanami::Config::Console]
|
|
195
|
+
#
|
|
196
|
+
# @api public
|
|
197
|
+
# @since 2.3.0
|
|
198
|
+
setting :console, default: Hanami::Config::Console.new
|
|
199
|
+
|
|
187
200
|
# Returns the app or slice's {Hanami::SliceName slice_name}.
|
|
188
201
|
#
|
|
189
202
|
# This is useful for default config values that depend on this name.
|
|
@@ -480,7 +493,7 @@ module Hanami
|
|
|
480
493
|
return if actions.formats.empty?
|
|
481
494
|
return if middleware.stack["/"].map(&:first).any? { |klass| klass == "Hanami::Middleware::BodyParser" }
|
|
482
495
|
|
|
483
|
-
parsers = SUPPORTED_MIDDLEWARE_PARSERS & actions.formats.
|
|
496
|
+
parsers = SUPPORTED_MIDDLEWARE_PARSERS & actions.formats.accepted
|
|
484
497
|
return if parsers.empty?
|
|
485
498
|
|
|
486
499
|
middleware.use(
|
data/lib/hanami/constants.rb
CHANGED
|
@@ -69,7 +69,8 @@ module Hanami
|
|
|
69
69
|
resolve_rom = method(:resolve_rom)
|
|
70
70
|
|
|
71
71
|
define_method(:new) do |**kwargs|
|
|
72
|
-
|
|
72
|
+
container = kwargs.delete(:container) || resolve_rom.()
|
|
73
|
+
super(container: container, **kwargs)
|
|
73
74
|
end
|
|
74
75
|
end
|
|
75
76
|
|
|
@@ -77,14 +78,18 @@ module Hanami
|
|
|
77
78
|
slice["db.rom"]
|
|
78
79
|
end
|
|
79
80
|
|
|
80
|
-
|
|
81
|
-
return unless repo_class.to_s.end_with?("Repo")
|
|
81
|
+
REPO_CLASS_NAME_REGEX = /^(?<name>.+)_(repo|repository)$/
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
def root_for_repo_class(repo_class)
|
|
84
|
+
repo_class_name = slice.inflector.demodulize(repo_class)
|
|
84
85
|
.then { slice.inflector.underscore(_1) }
|
|
85
|
-
|
|
86
|
+
|
|
87
|
+
repo_class_match = repo_class_name.match(REPO_CLASS_NAME_REGEX)
|
|
88
|
+
return unless repo_class_match
|
|
89
|
+
|
|
90
|
+
repo_class_match[:name]
|
|
86
91
|
.then { slice.inflector.pluralize(_1) }
|
|
87
|
-
.then
|
|
92
|
+
.then(&:to_sym)
|
|
88
93
|
end
|
|
89
94
|
|
|
90
95
|
def struct_namespace
|
|
@@ -90,28 +90,18 @@ module Hanami
|
|
|
90
90
|
# @since 2.1.0
|
|
91
91
|
attr_reader :inflector
|
|
92
92
|
|
|
93
|
-
# Returns the app's settings.
|
|
94
|
-
#
|
|
95
|
-
# @return [Hanami::Settings] the settings
|
|
96
|
-
#
|
|
97
|
-
# @api public
|
|
98
|
-
# @since 2.1.0
|
|
99
|
-
attr_reader :settings
|
|
100
|
-
|
|
101
93
|
# @see SliceConfiguredContext#define_new
|
|
102
94
|
#
|
|
103
95
|
# @api private
|
|
104
96
|
# @since 2.1.0
|
|
105
97
|
def initialize( # rubocop:disable Metrics/ParameterLists
|
|
106
98
|
inflector: nil,
|
|
107
|
-
settings: nil,
|
|
108
99
|
routes: nil,
|
|
109
100
|
assets: nil,
|
|
110
101
|
request: nil,
|
|
111
102
|
**args
|
|
112
103
|
)
|
|
113
104
|
@inflector = inflector
|
|
114
|
-
@settings = settings
|
|
115
105
|
@routes = routes
|
|
116
106
|
@assets = assets
|
|
117
107
|
@request = request
|
|
@@ -172,6 +162,16 @@ module Hanami
|
|
|
172
162
|
@request
|
|
173
163
|
end
|
|
174
164
|
|
|
165
|
+
# Returns true if the view is rendered from within an action and a request is available.
|
|
166
|
+
#
|
|
167
|
+
# @return [Boolean]
|
|
168
|
+
#
|
|
169
|
+
# @api public
|
|
170
|
+
# @since x.x.x
|
|
171
|
+
def request?
|
|
172
|
+
!!@request
|
|
173
|
+
end
|
|
174
|
+
|
|
175
175
|
# Returns the app's routes helper.
|
|
176
176
|
#
|
|
177
177
|
# @return [Hanami::Slice::RoutesHelper] the routes helper
|
|
@@ -37,18 +37,15 @@ module Hanami
|
|
|
37
37
|
#
|
|
38
38
|
# This includes the following app components:
|
|
39
39
|
# - the configured inflector as `inflector`
|
|
40
|
-
# - "settings" from the app container as `settings`
|
|
41
40
|
# - "routes" from the app container as `routes`
|
|
42
41
|
# - "assets" from the app container as `assets`
|
|
43
42
|
def define_new
|
|
44
43
|
inflector = slice.inflector
|
|
45
|
-
resolve_settings = method(:resolve_settings)
|
|
46
44
|
resolve_routes = method(:resolve_routes)
|
|
47
45
|
resolve_assets = method(:resolve_assets)
|
|
48
46
|
|
|
49
47
|
define_method :new do |**kwargs|
|
|
50
48
|
kwargs[:inflector] ||= inflector
|
|
51
|
-
kwargs[:settings] ||= resolve_settings.()
|
|
52
49
|
kwargs[:routes] ||= resolve_routes.()
|
|
53
50
|
kwargs[:assets] ||= resolve_assets.()
|
|
54
51
|
|
|
@@ -56,10 +53,6 @@ module Hanami
|
|
|
56
53
|
end
|
|
57
54
|
end
|
|
58
55
|
|
|
59
|
-
def resolve_settings
|
|
60
|
-
slice["settings"] if slice.key?("settings")
|
|
61
|
-
end
|
|
62
|
-
|
|
63
56
|
def resolve_routes
|
|
64
57
|
slice["routes"] if slice.key?("routes")
|
|
65
58
|
end
|