hanami 2.0.0.beta2 → 2.0.0.beta4

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.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -1
  3. data/hanami.gemspec +5 -5
  4. data/lib/hanami/app.rb +4 -4
  5. data/lib/hanami/assets/{app_configuration.rb → app_config.rb} +10 -10
  6. data/lib/hanami/assets/{configuration.rb → config.rb} +4 -4
  7. data/lib/hanami/{configuration → config}/actions/content_security_policy.rb +2 -2
  8. data/lib/hanami/{configuration → config}/actions/cookies.rb +6 -5
  9. data/lib/hanami/{configuration → config}/actions/sessions.rb +2 -2
  10. data/lib/hanami/{configuration → config}/actions.rb +11 -12
  11. data/lib/hanami/{configuration → config}/logger.rb +2 -2
  12. data/lib/hanami/config/null_config.rb +14 -0
  13. data/lib/hanami/{configuration → config}/router.rb +8 -8
  14. data/lib/hanami/{configuration → config}/sessions.rb +2 -2
  15. data/lib/hanami/{configuration → config}/views.rb +10 -10
  16. data/lib/hanami/{configuration.rb → config.rb} +30 -30
  17. data/lib/hanami/errors.rb +3 -0
  18. data/lib/hanami/extensions/action/slice_configured_action.rb +1 -1
  19. data/lib/hanami/providers/inflector.rb +0 -2
  20. data/lib/hanami/providers/logger.rb +1 -3
  21. data/lib/hanami/providers/rack.rb +0 -2
  22. data/lib/hanami/providers/routes.rb +0 -2
  23. data/lib/hanami/routes.rb +48 -21
  24. data/lib/hanami/settings/env_store.rb +3 -3
  25. data/lib/hanami/settings.rb +87 -5
  26. data/lib/hanami/slice/routing/middleware/stack.rb +45 -1
  27. data/lib/hanami/slice.rb +52 -37
  28. data/lib/hanami/slice_configurable.rb +1 -1
  29. data/lib/hanami/slice_registrar.rb +6 -0
  30. data/lib/hanami/version.rb +1 -1
  31. data/lib/hanami.rb +0 -1
  32. data/spec/{new_integration → integration}/action/cookies_spec.rb +0 -0
  33. data/spec/{new_integration → integration}/action/csrf_protection_spec.rb +0 -0
  34. data/spec/{new_integration → integration}/action/routes_spec.rb +3 -5
  35. data/spec/{new_integration → integration}/action/sessions_spec.rb +0 -0
  36. data/spec/{new_integration → integration}/action/slice_configuration_spec.rb +0 -0
  37. data/spec/{new_integration → integration}/action/view_integration_spec.rb +0 -0
  38. data/spec/{new_integration → integration}/action/view_rendering/automatic_rendering_spec.rb +0 -0
  39. data/spec/{new_integration → integration}/action/view_rendering/paired_view_inference_spec.rb +0 -0
  40. data/spec/{new_integration → integration}/action/view_rendering_spec.rb +0 -0
  41. data/spec/{new_integration → integration}/code_loading/loading_from_app_spec.rb +0 -0
  42. data/spec/{new_integration → integration}/code_loading/loading_from_lib_spec.rb +0 -0
  43. data/spec/{new_integration → integration}/code_loading/loading_from_slice_spec.rb +0 -0
  44. data/spec/{new_integration → integration}/container/application_routes_helper_spec.rb +1 -3
  45. data/spec/{new_integration → integration}/container/auto_injection_spec.rb +0 -0
  46. data/spec/{new_integration → integration}/container/auto_registration_spec.rb +0 -0
  47. data/spec/{new_integration → integration}/container/autoloader_spec.rb +0 -0
  48. data/spec/{new_integration → integration}/container/imports_spec.rb +0 -0
  49. data/spec/{new_integration → integration}/container/prepare_container_spec.rb +2 -0
  50. data/spec/{new_integration → integration}/container/shutdown_spec.rb +0 -0
  51. data/spec/{new_integration → integration}/container/standard_bootable_components_spec.rb +0 -0
  52. data/spec/{new_integration → integration}/dotenv_loading_spec.rb +0 -0
  53. data/spec/integration/rack_app/body_parser_spec.rb +108 -0
  54. data/spec/{new_integration → integration}/rack_app/middleware_spec.rb +37 -15
  55. data/spec/{new_integration → integration}/rack_app/non_booted_rack_app_spec.rb +3 -5
  56. data/spec/{new_integration → integration}/rack_app/rack_app_spec.rb +28 -48
  57. data/spec/integration/settings/access_in_slice_class_body_spec.rb +82 -0
  58. data/spec/integration/settings/access_to_constants_spec.rb +46 -0
  59. data/spec/{new_integration → integration}/settings/loading_from_env_spec.rb +0 -0
  60. data/spec/{new_integration → integration}/settings/settings_component_loading_spec.rb +0 -0
  61. data/spec/{new_integration/slices/slice_settings_spec.rb → integration/settings/slice_registration_spec.rb} +5 -1
  62. data/spec/{new_integration → integration}/settings/using_types_spec.rb +4 -11
  63. data/spec/{new_integration → integration}/setup_spec.rb +20 -0
  64. data/spec/{new_integration → integration}/slices/external_slice_spec.rb +2 -4
  65. data/spec/{new_integration → integration}/slices/slice_configuration_spec.rb +0 -0
  66. data/spec/{new_integration → integration}/slices/slice_loading_spec.rb +0 -0
  67. data/spec/{new_integration → integration}/slices/slice_routing_spec.rb +5 -13
  68. data/spec/{new_integration → integration}/slices_spec.rb +0 -0
  69. data/spec/{new_integration → integration}/view/context/assets_spec.rb +0 -0
  70. data/spec/{new_integration → integration}/view/context/inflector_spec.rb +0 -0
  71. data/spec/{new_integration → integration}/view/context/request_spec.rb +0 -0
  72. data/spec/{new_integration → integration}/view/context/routes_spec.rb +1 -3
  73. data/spec/{new_integration → integration}/view/context/settings_spec.rb +0 -0
  74. data/spec/{new_integration → integration}/view/inflector_spec.rb +0 -0
  75. data/spec/{new_integration → integration}/view/part_namespace_spec.rb +0 -0
  76. data/spec/{new_integration → integration}/view/path_spec.rb +0 -0
  77. data/spec/{new_integration → integration}/view/slice_configuration_spec.rb +0 -0
  78. data/spec/{new_integration → integration}/view/template_spec.rb +0 -0
  79. data/spec/{new_integration → integration}/view/views_spec.rb +0 -0
  80. data/spec/support/app_integration.rb +18 -15
  81. data/spec/unit/hanami/{configuration → config}/actions/content_security_policy_spec.rb +10 -10
  82. data/spec/unit/hanami/{configuration → config}/actions/cookies_spec.rb +6 -6
  83. data/spec/unit/hanami/{configuration → config}/actions/csrf_protection_spec.rb +12 -12
  84. data/spec/unit/hanami/config/actions/default_values_spec.rb +54 -0
  85. data/spec/unit/hanami/{configuration → config}/actions/sessions_spec.rb +5 -5
  86. data/spec/unit/hanami/{configuration → config}/actions_spec.rb +13 -25
  87. data/spec/unit/hanami/{configuration → config}/base_url_spec.rb +2 -2
  88. data/spec/unit/hanami/{configuration → config}/inflector_spec.rb +2 -2
  89. data/spec/unit/hanami/{configuration → config}/logger_spec.rb +4 -4
  90. data/spec/unit/hanami/config/router_spec.rb +44 -0
  91. data/spec/unit/hanami/{configuration → config}/slices_spec.rb +2 -2
  92. data/spec/unit/hanami/{configuration → config}/views_spec.rb +15 -27
  93. data/spec/unit/hanami/{configuration_spec.rb → config_spec.rb} +3 -3
  94. data/spec/unit/hanami/settings_spec.rb +65 -10
  95. data/spec/unit/hanami/slice_configurable_spec.rb +21 -2
  96. data/spec/unit/hanami/version_spec.rb +1 -1
  97. metadata +162 -294
  98. data/lib/hanami/configuration/null_configuration.rb +0 -14
  99. data/lib/hanami/providers/settings.rb +0 -98
  100. data/lib/hanami/server.rb +0 -29
  101. data/spec/integration/application_middleware_stack_spec.rb +0 -84
  102. data/spec/integration/assets/cdn_spec.rb +0 -48
  103. data/spec/integration/assets/fingerprint_spec.rb +0 -42
  104. data/spec/integration/assets/helpers_spec.rb +0 -50
  105. data/spec/integration/assets/serve_spec.rb +0 -70
  106. data/spec/integration/assets/subresource_integrity_spec.rb +0 -54
  107. data/spec/integration/body_parsers_spec.rb +0 -50
  108. data/spec/integration/cli/assets/precompile_spec.rb +0 -147
  109. data/spec/integration/cli/assets_spec.rb +0 -14
  110. data/spec/integration/cli/console_spec.rb +0 -105
  111. data/spec/integration/cli/db/apply_spec.rb +0 -74
  112. data/spec/integration/cli/db/console_spec.rb +0 -40
  113. data/spec/integration/cli/db/create_spec.rb +0 -50
  114. data/spec/integration/cli/db/drop_spec.rb +0 -54
  115. data/spec/integration/cli/db/migrate_spec.rb +0 -108
  116. data/spec/integration/cli/db/prepare_spec.rb +0 -36
  117. data/spec/integration/cli/db/rollback_spec.rb +0 -96
  118. data/spec/integration/cli/db/version_spec.rb +0 -38
  119. data/spec/integration/cli/db_spec.rb +0 -21
  120. data/spec/integration/cli/destroy/action_spec.rb +0 -143
  121. data/spec/integration/cli/destroy/app_spec.rb +0 -118
  122. data/spec/integration/cli/destroy/mailer_spec.rb +0 -74
  123. data/spec/integration/cli/destroy/migration_spec.rb +0 -70
  124. data/spec/integration/cli/destroy/model_spec.rb +0 -113
  125. data/spec/integration/cli/destroy_spec.rb +0 -18
  126. data/spec/integration/cli/generate/action_spec.rb +0 -469
  127. data/spec/integration/cli/generate/app_spec.rb +0 -215
  128. data/spec/integration/cli/generate/mailer_spec.rb +0 -189
  129. data/spec/integration/cli/generate/migration_spec.rb +0 -72
  130. data/spec/integration/cli/generate/model_spec.rb +0 -290
  131. data/spec/integration/cli/generate/secret_spec.rb +0 -56
  132. data/spec/integration/cli/generate_spec.rb +0 -19
  133. data/spec/integration/cli/new/database_spec.rb +0 -235
  134. data/spec/integration/cli/new/hanami_head_spec.rb +0 -27
  135. data/spec/integration/cli/new/template_spec.rb +0 -118
  136. data/spec/integration/cli/new/test_spec.rb +0 -274
  137. data/spec/integration/cli/new_spec.rb +0 -970
  138. data/spec/integration/cli/plugins_spec.rb +0 -39
  139. data/spec/integration/cli/routes_spec.rb +0 -49
  140. data/spec/integration/cli/server_spec.rb +0 -626
  141. data/spec/integration/cli/version_spec.rb +0 -85
  142. data/spec/integration/early_hints_spec.rb +0 -35
  143. data/spec/integration/handle_exceptions_spec.rb +0 -244
  144. data/spec/integration/head_spec.rb +0 -89
  145. data/spec/integration/http_headers_spec.rb +0 -29
  146. data/spec/integration/mailer_spec.rb +0 -32
  147. data/spec/integration/middleware_spec.rb +0 -81
  148. data/spec/integration/mount_applications_spec.rb +0 -88
  149. data/spec/integration/project_initializers_spec.rb +0 -40
  150. data/spec/integration/rackup_spec.rb +0 -35
  151. data/spec/integration/rake/with_minitest_spec.rb +0 -67
  152. data/spec/integration/rake/with_rspec_spec.rb +0 -69
  153. data/spec/integration/routing_helpers_spec.rb +0 -61
  154. data/spec/integration/security/content_security_policy_spec.rb +0 -46
  155. data/spec/integration/security/csrf_protection_spec.rb +0 -42
  156. data/spec/integration/security/force_ssl_spec.rb +0 -29
  157. data/spec/integration/security/x_content_type_options_spec.rb +0 -46
  158. data/spec/integration/security/x_frame_options_spec.rb +0 -46
  159. data/spec/integration/security/x_xss_protection_spec.rb +0 -46
  160. data/spec/integration/send_file_spec.rb +0 -51
  161. data/spec/integration/sessions_spec.rb +0 -247
  162. data/spec/integration/static_middleware_spec.rb +0 -21
  163. data/spec/integration/streaming_spec.rb +0 -41
  164. data/spec/integration/unsafe_send_file_spec.rb +0 -52
  165. data/spec/new_integration/settings/access_to_constants_spec.rb +0 -169
  166. data/spec/support/fixtures/hanami-plugin/Gemfile +0 -8
  167. data/spec/support/fixtures/hanami-plugin/README.md +0 -35
  168. data/spec/support/fixtures/hanami-plugin/Rakefile +0 -4
  169. data/spec/support/fixtures/hanami-plugin/bin/console +0 -15
  170. data/spec/support/fixtures/hanami-plugin/bin/setup +0 -8
  171. data/spec/support/fixtures/hanami-plugin/hanami-plugin.gemspec +0 -28
  172. data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/cli.rb +0 -19
  173. data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/version.rb +0 -7
  174. data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin.rb +0 -8
  175. data/spec/unit/hanami/configuration/actions/default_values_spec.rb +0 -52
  176. data/spec/unit/hanami/routes_spec.rb +0 -25
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e9e5c35a72383ba29d2523a9b30da2a3170605bba5cee20562c897025a58524
4
- data.tar.gz: 328e2e6aa30db94ce7dbae5f58d3ac0ce8435ec928ed71fa058345ca3a22553f
3
+ metadata.gz: afcc32f5e8f7ba0a0acb001c4c36ea5a654f73e705b22e73cfc2a2835858af3e
4
+ data.tar.gz: d183f4cdec177426f339eeae371320880927d15463982d82daeffacd632fe09f
5
5
  SHA512:
6
- metadata.gz: 769a484cea4c2594afaece8ae368e16003d02f988b6c015370b0b8236de477042611d71432da8d89d885ebabd3e0e013e7dd9299d0622897f44ac3d511980daf
7
- data.tar.gz: e5808f8d9195cb242cbc02d136c993167ab124dabda9b239469841c981c621410d80ace966378157f22cdfd4aaf683f885257d96713561e2e12ce54cdadcab0f
6
+ metadata.gz: a1cca2e0e675ba87e678c14d4733bc172af135ea8fbf751fb1d1749faef2cf9a96629eae77fac339c5d435f6d3744dc6da1f1c32bf63881563ceb435337725bb
7
+ data.tar.gz: 5a466e081c89ded4a30f4ba8655c2981ba26f9cbb16a5f5e8deb6034f806f4ec203a62556c4ad372b8fd4619e959eb8beb3781a6e8e0451e04aaa0dc2099129f
data/CHANGELOG.md CHANGED
@@ -2,6 +2,34 @@
2
2
 
3
3
  The web, with simplicity.
4
4
 
5
+ ## v2.0.0.beta4 - 2022-10-24
6
+
7
+ ### Added
8
+
9
+ - [Peter Solnica] Improve middleware config by avoiding class names and requires: symbols instead of classes can be passed as middleware identifiers (`config.middleware.use(:body_parser, :json)`); constant namespaces can be configured for resolving symbols into class names (`config.middleware.namespaces = [Hanami::Middleware, MyStuff::Middlewares]`), with the first match winning; first-party middleware classes are required automatically. (#1215)
10
+
11
+ ### Fixed
12
+
13
+ - [Luca Guidi] Do not attempt to load routes if hanami-router is not bundled (#1214)
14
+ - [Marc Busqué] Ensure nested slices are considered when auto-configuring application components using `Hanami::SliceConfigurable` (#1212)
15
+ - [Tim Riley] Ensure errors are raised during settings loading for any settings that are missing entirely from ENV (#1222)
16
+
17
+ ### Changed
18
+
19
+ - [Tim Riley] Rename `Hanami::App.configuration` to `Hanami::App.config` and `Hanami::Configuration` to `Hanami::Config` (#1218)
20
+ - [Tim Riley] Make `Hanami::App.settings` available as a class method again (#1213)
21
+ - [Tim Riley] `config/settings.rb` in apps no longer has access to autoloaded constants (changed back to behavior pre-beta3) (#1213)
22
+ - [Tim Riley] Auto-generate a nested `Types` module in `Hanami::Settings` subclasses if dry-types is available, for added convenience in type checking settings (#1213)
23
+ - [Marc Busqué] Hide values from `Hanami::Settings#inspect` (values may contain sensitive data). Values can be inspected via `#inspect_values` (#1217)
24
+
25
+ ## v2.0.0.beta3 - 2022-09-21
26
+
27
+ ### Changed
28
+
29
+ - [Piotr Solnica] Simplify routes definition, by removing `routes` block from `config/routes.rb`
30
+
31
+ ### Added
32
+
5
33
  ## v2.0.0.beta2 - 2022-08-16
6
34
 
7
35
  ### Added
@@ -25,6 +53,7 @@ The web, with simplicity.
25
53
  Or by setting `HANAMI_SLICES=blog,shop` in the env.
26
54
 
27
55
  You can also specify arbitrarily nested slices using dot delimiters. For example, if you have an `admin` slice with nested `shop` and `blog` slices, you can specify `config.slices = %w[admin.shop]` to only load the admin slice and its nested shop slice.
56
+
28
57
  - [Tim Riley] Added `App.prepare_load_path`, which need only be called if you explicitly change your app's `config.root`. The `$LOAD_PATH` is otherwise still prepared automatically for the default `root` of `Dir.pwd`. [#1188]
29
58
  - [Marc Busqué, Tim Riley] Added `Hanami.setup` to find and load your Hanami app file (expected at `config/app.rb`). This will search in the current directory, and will search upwards through parent directories until the app file is found. [#1197]
30
59
 
@@ -62,6 +91,7 @@ The web, with simplicity.
62
91
  end
63
92
  end
64
93
  ```
94
+
65
95
  - [Tim Riley] Every slice has a distinct `Zeitwerk::Loader` instance at `Slice.autoloader`. This change enabled the autoloading within settings described above. [#1186]
66
96
  - [Tim Riley] `Slice.settings` reader method has been removed. Access settings via `App["settings"]` or `Slice["settings"]` (after the slice has been prepared) instead. [#1186]
67
97
  - [Tim Riley] dry-types is no longer a dependency specified in the gemspec. This is made available to generated app via a line in their `Gemfile` instead. [#1186]
@@ -133,7 +163,6 @@ The web, with simplicity.
133
163
  - [Tim Riley] Removed `Hanami::Configuration::Router#routes_path`, and `#routes_class_name` [#1175]
134
164
  - [Tim Riley] Make `Hanami::App` to inherit from `Hanami::Slice` [#1162]
135
165
 
136
-
137
166
  ## v2.0.0.alpha8 - 2022-05-19
138
167
 
139
168
  ### Added
data/hanami.gemspec CHANGED
@@ -32,14 +32,14 @@ Gem::Specification.new do |spec|
32
32
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
33
33
 
34
34
  spec.add_dependency "bundler", ">= 1.16", "< 3"
35
- spec.add_dependency "dry-configurable", "~> 0.15"
36
- spec.add_dependency "dry-core", "~> 0.7"
35
+ spec.add_dependency "dry-configurable", "~> 0.16", ">= 0.16.1"
36
+ spec.add_dependency "dry-core", "~> 0.9", ">= 0.9.1"
37
37
  spec.add_dependency "dry-inflector", "~> 0.2", ">= 0.2.1"
38
- spec.add_dependency "dry-system", "~> 0.25", ">= 0.25.0"
39
- spec.add_dependency "dry-monitor", "~> 0.6", ">= 0.6.3"
38
+ spec.add_dependency "dry-system", "~> 0.27", ">= 0.27.2"
39
+ spec.add_dependency "dry-monitor", "~> 0.7", ">= 0.7"
40
40
  spec.add_dependency "hanami-cli", "~> 2.0.beta"
41
41
  spec.add_dependency "hanami-utils", "~> 2.0.beta"
42
- spec.add_dependency "zeitwerk", "~> 2.4"
42
+ spec.add_dependency "zeitwerk", "~> 2.6"
43
43
 
44
44
  spec.add_development_dependency "rspec", "~> 3.8"
45
45
  spec.add_development_dependency "rack-test", "~> 1.1"
data/lib/hanami/app.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "configuration"
3
+ require_relative "config"
4
4
  require_relative "constants"
5
5
  require_relative "slice"
6
6
  require_relative "slice_name"
@@ -29,7 +29,7 @@ module Hanami
29
29
 
30
30
  @_mutex.synchronize do
31
31
  subclass.class_eval do
32
- @configuration = Hanami::Configuration.new(app_name: slice_name, env: Hanami.env)
32
+ @config = Hanami::Config.new(app_name: slice_name, env: Hanami.env)
33
33
 
34
34
  # Prepare the load path (based on the default root of `Dir.pwd`) as early as
35
35
  # possible, so you can make a `require` inside the body of an `App` subclass,
@@ -43,7 +43,7 @@ module Hanami
43
43
 
44
44
  # App class interface
45
45
  module ClassMethods
46
- attr_reader :configuration
46
+ attr_reader :config
47
47
 
48
48
  def app_name
49
49
  slice_name
@@ -152,7 +152,7 @@ module Hanami
152
152
 
153
153
  # When auto-registering components in app/, ignore files in `app/lib/` (these will
154
154
  # be auto-registered as above), as well as the configured no_auto_register_paths
155
- no_auto_register_paths = ([LIB_DIR] + configuration.no_auto_register_paths)
155
+ no_auto_register_paths = ([LIB_DIR] + config.no_auto_register_paths)
156
156
  .map { |path|
157
157
  path.end_with?(File::SEPARATOR) ? path : "#{path}#{File::SEPARATOR}"
158
158
  }
@@ -1,19 +1,19 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "hanami/assets/configuration"
4
3
  require "dry/configurable"
4
+ require_relative "config"
5
5
 
6
6
  module Hanami
7
7
  module Assets
8
8
  # @since 2.0.0
9
9
  # @api public
10
- class AppConfiguration
10
+ class AppConfig
11
11
  include Dry::Configurable
12
12
 
13
13
  # @since 2.0.0
14
14
  # @api private
15
- attr_reader :base_configuration
16
- protected :base_configuration
15
+ attr_reader :base_config
16
+ protected :base_config
17
17
 
18
18
  setting :server_url, default: "http://localhost:8080"
19
19
 
@@ -22,12 +22,12 @@ module Hanami
22
22
  def initialize(*)
23
23
  super
24
24
 
25
- @base_configuration = Assets::Configuration.new
25
+ @base_config = Config.new
26
26
  end
27
27
 
28
28
  def initialize_copy(source)
29
29
  super
30
- @base_configuration = source.base_configuration.dup
30
+ @base_config = source.base_config.dup
31
31
  end
32
32
 
33
33
  # @since 2.0.0
@@ -42,7 +42,7 @@ module Hanami
42
42
  # @since 2.0.0
43
43
  # @api private
44
44
  def settings
45
- base_configuration.settings + self.class.settings
45
+ base_config.settings + self.class.settings
46
46
  end
47
47
 
48
48
  private
@@ -52,8 +52,8 @@ module Hanami
52
52
  def method_missing(name, *args, &block)
53
53
  if config.respond_to?(name)
54
54
  config.public_send(name, *args, &block)
55
- elsif base_configuration.respond_to?(name)
56
- base_configuration.public_send(name, *args, &block)
55
+ elsif base_config.respond_to?(name)
56
+ base_config.public_send(name, *args, &block)
57
57
  else
58
58
  super
59
59
  end
@@ -62,7 +62,7 @@ module Hanami
62
62
  # @since 2.0.0
63
63
  # @api private
64
64
  def respond_to_missing?(name, _incude_all = false)
65
- config.respond_to?(name) || base_configuration.respond_to?(name) || super
65
+ config.respond_to?(name) || base_config.respond_to?(name) || super
66
66
  end
67
67
  end
68
68
  end
@@ -6,14 +6,14 @@ module Hanami
6
6
  module Assets
7
7
  # @since 2.0.0
8
8
  # @api public
9
- class Configuration
9
+ class Config
10
10
  include Dry::Configurable
11
11
 
12
- # Initialize the Configuration
12
+ # Initialize the Config
13
13
  #
14
- # @yield [config] the configuration object
14
+ # @yield [config] the config object
15
15
  #
16
- # @return [Configuration]
16
+ # @return [Config]
17
17
  #
18
18
  # @since 2.0.0
19
19
  # @api private
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hanami
4
- class Configuration
4
+ class Config
5
5
  class Actions
6
- # Configuration for Content Security Policy in Hanami apps
6
+ # Config for Content Security Policy in Hanami apps
7
7
  #
8
8
  # @since 2.0.0
9
9
  class ContentSecurityPolicy
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hanami
4
- class Configuration
4
+ class Config
5
5
  class Actions
6
- # Wrapper for app-level configuration of HTTP cookies for Hanami actions.
7
- # This decorates the hash of cookie options that is otherwise directly configurable
8
- # on actions, and adds the `enabled?` method to allow app base action to
9
- # determine whether to include the `Action::Cookies` module.
6
+ # Wrapper for app-level config of HTTP cookies for Hanami actions.
7
+ #
8
+ # This decorates the hash of cookie options that is otherwise directly configurable on
9
+ # actions, and adds the `enabled?` method to allow app base action to determine whether to
10
+ # include the `Action::Cookies` module.
10
11
  #
11
12
  # @since 2.0.0
12
13
  class Cookies
@@ -5,9 +5,9 @@ require "hanami/utils/string"
5
5
  require "hanami/utils/class"
6
6
 
7
7
  module Hanami
8
- class Configuration
8
+ class Config
9
9
  class Actions
10
- # Configuration for HTTP sessions in Hanami actions
10
+ # Config for HTTP sessions in Hanami actions
11
11
  #
12
12
  # @since 2.0.0
13
13
  class Sessions
@@ -1,15 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry/configurable"
4
- require "hanami/action/configuration"
5
4
  require_relative "actions/cookies"
6
5
  require_relative "actions/sessions"
7
6
  require_relative "actions/content_security_policy"
8
7
  require_relative "../slice/view_name_inferrer"
9
8
 
10
9
  module Hanami
11
- class Configuration
12
- # Hanami actions configuration
10
+ class Config
11
+ # Hanami actions config
13
12
  #
14
13
  # @since 2.0.0
15
14
  class Actions
@@ -26,13 +25,13 @@ module Hanami
26
25
 
27
26
  attr_accessor :content_security_policy
28
27
 
29
- attr_reader :base_configuration
30
- protected :base_configuration
28
+ attr_reader :base_config
29
+ protected :base_config
31
30
 
32
31
  def initialize(*, **options)
33
32
  super()
34
33
 
35
- @base_configuration = Hanami::Action::Configuration.new
34
+ @base_config = Hanami::Action.config.dup
36
35
  @content_security_policy = ContentSecurityPolicy.new do |csp|
37
36
  if assets_server_url = options[:assets_server_url]
38
37
  csp[:script_src] += " #{assets_server_url}"
@@ -45,7 +44,7 @@ module Hanami
45
44
 
46
45
  def initialize_copy(source)
47
46
  super
48
- @base_configuration = source.base_configuration.dup
47
+ @base_config = source.base_config.dup
49
48
  @content_security_policy = source.content_security_policy.dup
50
49
  end
51
50
 
@@ -66,12 +65,12 @@ module Hanami
66
65
  # @since 2.0.0
67
66
  # @api private
68
67
  def settings
69
- base_configuration.settings + self.class.settings
68
+ Hanami::Action.settings + self.class.settings
70
69
  end
71
70
 
72
71
  private
73
72
 
74
- # Apply defaults for base configuration settings
73
+ # Apply defaults for base config
75
74
  def configure_defaults
76
75
  self.default_request_format = :html
77
76
  self.default_response_format = :html
@@ -86,15 +85,15 @@ module Hanami
86
85
  def method_missing(name, *args, &block)
87
86
  if config.respond_to?(name)
88
87
  config.public_send(name, *args, &block)
89
- elsif base_configuration.respond_to?(name)
90
- base_configuration.public_send(name, *args, &block)
88
+ elsif base_config.respond_to?(name)
89
+ base_config.public_send(name, *args, &block)
91
90
  else
92
91
  super
93
92
  end
94
93
  end
95
94
 
96
95
  def respond_to_missing?(name, _incude_all = false)
97
- config.respond_to?(name) || base_configuration.respond_to?(name) || super
96
+ config.respond_to?(name) || base_config.respond_to?(name) || super
98
97
  end
99
98
  end
100
99
  end
@@ -4,8 +4,8 @@ require "dry/configurable"
4
4
  require "hanami/logger"
5
5
 
6
6
  module Hanami
7
- class Configuration
8
- # Hanami logger configuration
7
+ class Config
8
+ # Hanami logger config
9
9
  #
10
10
  # @since 2.0.0
11
11
  class Logger
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/configurable"
4
+
5
+ module Hanami
6
+ class Config
7
+ # NullConfig can serve as a fallback config object when out-of-gem config objects are not
8
+ # available (specifically, when the hanami-controller, hanami-router or hanami-view gems are not
9
+ # loaded)
10
+ class NullConfig
11
+ include Dry::Configurable
12
+ end
13
+ end
14
+ end
@@ -4,22 +4,22 @@ require "dry/configurable"
4
4
  require_relative "../slice/routing/resolver"
5
5
 
6
6
  module Hanami
7
- class Configuration
8
- # Hanami router configuration
7
+ class Config
8
+ # Hanami router config
9
9
  #
10
10
  # @since 2.0.0
11
11
  # @api private
12
12
  class Router
13
13
  include Dry::Configurable
14
14
 
15
- # Base configuration is provided so router config can include the `base_url`
16
- attr_reader :base_configuration
17
- private :base_configuration
15
+ # Base config is provided so router config can include the `base_url`
16
+ attr_reader :base_config
17
+ private :base_config
18
18
 
19
19
  # @api private
20
20
  # @since 2.0.0
21
- def initialize(base_configuration)
22
- @base_configuration = base_configuration
21
+ def initialize(base_config)
22
+ @base_config = base_config
23
23
  end
24
24
 
25
25
  setting :resolver, default: Slice::Routing::Resolver
@@ -27,7 +27,7 @@ module Hanami
27
27
  # @api private
28
28
  # @since 2.0.0
29
29
  def options
30
- {base_url: base_configuration.base_url}
30
+ {base_url: base_config.base_url}
31
31
  end
32
32
 
33
33
  private
@@ -4,8 +4,8 @@ require "hanami/utils/string"
4
4
  require "hanami/utils/class"
5
5
 
6
6
  module Hanami
7
- class Configuration
8
- # Hanami configuration for HTTP sessions
7
+ class Config
8
+ # Hanami config for HTTP sessions
9
9
  #
10
10
  # @since 2.0.0
11
11
  class Sessions
@@ -4,8 +4,8 @@ require "dry/configurable"
4
4
  require "hanami/view"
5
5
 
6
6
  module Hanami
7
- class Configuration
8
- # Hanami actions configuration
7
+ class Config
8
+ # Hanami views config
9
9
  #
10
10
  # @since 2.0.0
11
11
  class Views
@@ -13,20 +13,20 @@ module Hanami
13
13
 
14
14
  setting :parts_path, default: "views/parts"
15
15
 
16
- attr_reader :base_configuration
17
- protected :base_configuration
16
+ attr_reader :base_config
17
+ protected :base_config
18
18
 
19
19
  def initialize(*)
20
20
  super
21
21
 
22
- @base_configuration = Hanami::View.config.dup
22
+ @base_config = Hanami::View.config.dup
23
23
 
24
24
  configure_defaults
25
25
  end
26
26
 
27
27
  def initialize_copy(source)
28
28
  super
29
- @base_configuration = source.base_configuration.dup
29
+ @base_config = source.base_config.dup
30
30
  end
31
31
 
32
32
  # Returns the list of available settings
@@ -42,7 +42,7 @@ module Hanami
42
42
  def finalize!
43
43
  return self if frozen?
44
44
 
45
- base_configuration.finalize!
45
+ base_config.finalize!
46
46
 
47
47
  super
48
48
  end
@@ -69,8 +69,8 @@ module Hanami
69
69
 
70
70
  if config.respond_to?(name)
71
71
  config.public_send(name, *args, &block)
72
- elsif base_configuration.respond_to?(name)
73
- base_configuration.public_send(name, *args, &block)
72
+ elsif base_config.respond_to?(name)
73
+ base_config.public_send(name, *args, &block)
74
74
  else
75
75
  super
76
76
  end
@@ -79,7 +79,7 @@ module Hanami
79
79
  def respond_to_missing?(name, _include_all = false)
80
80
  return false if NON_FORWARDABLE_METHODS.include?(name)
81
81
 
82
- config.respond_to?(name) || base_configuration.respond_to?(name) || super
82
+ config.respond_to?(name) || base_config.respond_to?(name) || super
83
83
  end
84
84
  end
85
85
  end
@@ -8,9 +8,8 @@ require "dry/inflector"
8
8
  require "pathname"
9
9
 
10
10
  require_relative "constants"
11
- require_relative "configuration/logger"
12
- require_relative "configuration/router"
13
- require_relative "configuration/sessions"
11
+ require_relative "config/logger"
12
+ require_relative "config/sessions"
14
13
  require_relative "settings/env_store"
15
14
  require_relative "slice/routing/middleware/stack"
16
15
 
@@ -18,7 +17,7 @@ module Hanami
18
17
  # Hanami app configuration
19
18
  #
20
19
  # @since 2.0.0
21
- class Configuration
20
+ class Config
22
21
  include Dry::Configurable
23
22
 
24
23
  setting :root, constructor: ->(path) { Pathname(path) if path }
@@ -59,7 +58,7 @@ module Hanami
59
58
  # @api public
60
59
  attr_reader :env
61
60
 
62
- # @return [Hanami::Configuration::Actions]
61
+ # @return [Hanami::Config::Actions]
63
62
  #
64
63
  # @api public
65
64
  attr_reader :actions
@@ -72,12 +71,12 @@ module Hanami
72
71
  # @api private
73
72
  alias_method :middleware_stack, :middleware
74
73
 
75
- # @return [Hanami::Configuration::Router]
74
+ # @return [Hanami::Config::Router]
76
75
  #
77
76
  # @api public
78
77
  attr_reader :router
79
78
 
80
- # @return [Hanami::Configuration::Views]
79
+ # @return [Hanami::Config::Views]
81
80
  #
82
81
  # @api public
83
82
  attr_reader :views
@@ -104,34 +103,36 @@ module Hanami
104
103
  self.root = Dir.pwd
105
104
  load_from_env
106
105
 
107
- config.logger = Configuration::Logger.new(env: env, app_name: app_name)
106
+ config.logger = Config::Logger.new(env: env, app_name: app_name)
108
107
 
109
- @assets = load_dependent_config("hanami/assets/app_configuration") {
110
- Hanami::Assets::AppConfiguration.new
111
- }
108
+ # TODO: Make assets config dependent
109
+ require "hanami/assets/app_config"
110
+ @assets = Hanami::Assets::AppConfig.new
112
111
 
113
- @actions = load_dependent_config("hanami/action") {
114
- require_relative "configuration/actions"
112
+ @actions = load_dependent_config("hanami-controller") {
113
+ require_relative "config/actions"
115
114
  Actions.new
116
115
  }
117
116
 
118
- @middleware = Slice::Routing::Middleware::Stack.new
119
-
120
- @router = Router.new(self)
117
+ @router = load_dependent_config("hanami-router") {
118
+ require_relative "config/router"
119
+ @middleware = Slice::Routing::Middleware::Stack.new
120
+ Router.new(self)
121
+ }
121
122
 
122
- @views = load_dependent_config("hanami/view") {
123
- require_relative "configuration/views"
123
+ @views = load_dependent_config("hanami-view") {
124
+ require_relative "config/views"
124
125
  Views.new
125
126
  }
126
127
 
127
128
  yield self if block_given?
128
129
  end
129
130
 
130
- # Apply configuration for the given environment
131
+ # Apply config for the given environment
131
132
  #
132
133
  # @param env [String] the environment name
133
134
  #
134
- # @return [Hanami::Configuration]
135
+ # @return [Hanami::Config]
135
136
  #
136
137
  # @api public
137
138
  def environment(env_name, &block)
@@ -163,7 +164,7 @@ module Hanami
163
164
  @actions = source.actions.dup
164
165
  @middleware = source.middleware.dup
165
166
  @router = source.router.dup.tap do |router|
166
- router.instance_variable_set(:@base_configuration, self)
167
+ router.instance_variable_set(:@base_config, self)
167
168
  end
168
169
  @views = source.views.dup
169
170
  end
@@ -172,7 +173,7 @@ module Hanami
172
173
  def finalize!
173
174
  apply_env_config
174
175
 
175
- # Finalize nested configurations
176
+ # Finalize nested configs
176
177
  assets.finalize!
177
178
  actions.finalize!
178
179
  views.finalize!
@@ -209,14 +210,13 @@ module Hanami
209
210
  end
210
211
 
211
212
  # @api private
212
- def load_dependent_config(require_path)
213
- require require_path
214
- yield
215
- rescue LoadError => e
216
- raise e unless e.path == require_path
217
-
218
- require_relative "configuration/null_configuration"
219
- NullConfiguration.new
213
+ def load_dependent_config(gem_name)
214
+ if Hanami.bundled?(gem_name)
215
+ yield
216
+ else
217
+ require_relative "config/null_config"
218
+ NullConfig.new
219
+ end
220
220
  end
221
221
 
222
222
  def method_missing(name, *args, &block)
data/lib/hanami/errors.rb CHANGED
@@ -12,4 +12,7 @@ module Hanami
12
12
 
13
13
  # @since 2.0.0
14
14
  ComponentLoadError = Class.new(Error)
15
+
16
+ # @since 2.0.0
17
+ UnsupportedMiddlewareSpecError = Class.new(Error)
15
18
  end
@@ -47,7 +47,7 @@ module Hanami
47
47
  end
48
48
 
49
49
  def configure_action(action_class)
50
- action_class.config.settings.each do |setting|
50
+ action_class.settings.each do |setting|
51
51
  # Configure the action from config on the slice, _unless it has already been configured
52
52
  # by a parent slice_, and re-configuring it for this slice would make no change.
53
53
  #
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/system/provider/source"
4
-
5
3
  module Hanami
6
4
  module Providers
7
5
  class Inflector < Dry::System::Provider::Source
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/system/provider/source"
4
-
5
3
  module Hanami
6
4
  module Providers
7
5
  class Logger < Dry::System::Provider::Source
8
6
  def start
9
- register :logger, Hanami.app.configuration.logger_instance
7
+ register :logger, Hanami.app.config.logger_instance
10
8
  end
11
9
  end
12
10
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "dry/system/provider/source"
4
-
5
3
  module Hanami
6
4
  module Providers
7
5
  class Rack < Dry::System::Provider::Source