piko-lite-box 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.
Files changed (99) hide show
  1. checksums.yaml +7 -0
  2. data/hanami-3.0.1/CHANGELOG.md +1701 -0
  3. data/hanami-3.0.1/LICENSE +20 -0
  4. data/hanami-3.0.1/README.md +89 -0
  5. data/hanami-3.0.1/hanami.gemspec +49 -0
  6. data/hanami-3.0.1/lib/hanami/app.rb +197 -0
  7. data/hanami-3.0.1/lib/hanami/boot.rb +5 -0
  8. data/hanami-3.0.1/lib/hanami/config/actions/content_security_policy.rb +140 -0
  9. data/hanami-3.0.1/lib/hanami/config/actions/cookies.rb +57 -0
  10. data/hanami-3.0.1/lib/hanami/config/actions/sessions.rb +83 -0
  11. data/hanami-3.0.1/lib/hanami/config/actions.rb +189 -0
  12. data/hanami-3.0.1/lib/hanami/config/assets.rb +84 -0
  13. data/hanami-3.0.1/lib/hanami/config/console.rb +79 -0
  14. data/hanami-3.0.1/lib/hanami/config/db.rb +35 -0
  15. data/hanami-3.0.1/lib/hanami/config/i18n.rb +138 -0
  16. data/hanami-3.0.1/lib/hanami/config/logger.rb +207 -0
  17. data/hanami-3.0.1/lib/hanami/config/null_config.rb +17 -0
  18. data/hanami-3.0.1/lib/hanami/config/router.rb +48 -0
  19. data/hanami-3.0.1/lib/hanami/config/views.rb +103 -0
  20. data/hanami-3.0.1/lib/hanami/config.rb +564 -0
  21. data/hanami-3.0.1/lib/hanami/constants.rb +62 -0
  22. data/hanami-3.0.1/lib/hanami/env.rb +52 -0
  23. data/hanami-3.0.1/lib/hanami/errors.rb +41 -0
  24. data/hanami-3.0.1/lib/hanami/extensions/action/i18n_helper.rb +64 -0
  25. data/hanami-3.0.1/lib/hanami/extensions/action/name_inferrer.rb +34 -0
  26. data/hanami-3.0.1/lib/hanami/extensions/action/slice_configured_action.rb +190 -0
  27. data/hanami-3.0.1/lib/hanami/extensions/action.rb +147 -0
  28. data/hanami-3.0.1/lib/hanami/extensions/db/repo.rb +108 -0
  29. data/hanami-3.0.1/lib/hanami/extensions/mailer/slice_configured_mailer.rb +134 -0
  30. data/hanami-3.0.1/lib/hanami/extensions/mailer.rb +28 -0
  31. data/hanami-3.0.1/lib/hanami/extensions/operation/slice_configured_db_operation.rb +90 -0
  32. data/hanami-3.0.1/lib/hanami/extensions/operation.rb +33 -0
  33. data/hanami-3.0.1/lib/hanami/extensions/router/errors.rb +58 -0
  34. data/hanami-3.0.1/lib/hanami/extensions/view/context.rb +298 -0
  35. data/hanami-3.0.1/lib/hanami/extensions/view/part.rb +92 -0
  36. data/hanami-3.0.1/lib/hanami/extensions/view/scope.rb +36 -0
  37. data/hanami-3.0.1/lib/hanami/extensions/view/slice_configured_context.rb +73 -0
  38. data/hanami-3.0.1/lib/hanami/extensions/view/slice_configured_helpers.rb +55 -0
  39. data/hanami-3.0.1/lib/hanami/extensions/view/slice_configured_part.rb +73 -0
  40. data/hanami-3.0.1/lib/hanami/extensions/view/slice_configured_view.rb +243 -0
  41. data/hanami-3.0.1/lib/hanami/extensions/view/standard_helpers.rb +26 -0
  42. data/hanami-3.0.1/lib/hanami/extensions/view.rb +38 -0
  43. data/hanami-3.0.1/lib/hanami/extensions.rb +30 -0
  44. data/hanami-3.0.1/lib/hanami/helpers/assets_helper.rb +804 -0
  45. data/hanami-3.0.1/lib/hanami/helpers/form_helper/form_builder.rb +1389 -0
  46. data/hanami-3.0.1/lib/hanami/helpers/form_helper/values.rb +75 -0
  47. data/hanami-3.0.1/lib/hanami/helpers/form_helper.rb +213 -0
  48. data/hanami-3.0.1/lib/hanami/helpers/i18n_helper.rb +241 -0
  49. data/hanami-3.0.1/lib/hanami/logger/rack_formatter.rb +73 -0
  50. data/hanami-3.0.1/lib/hanami/logger/sql_formatter.rb +80 -0
  51. data/hanami-3.0.1/lib/hanami/logger/sql_logger.rb +48 -0
  52. data/hanami-3.0.1/lib/hanami/middleware/assets.rb +21 -0
  53. data/hanami-3.0.1/lib/hanami/middleware/content_security_policy_nonce.rb +53 -0
  54. data/hanami-3.0.1/lib/hanami/middleware/public_errors_app.rb +75 -0
  55. data/hanami-3.0.1/lib/hanami/middleware/render_errors.rb +90 -0
  56. data/hanami-3.0.1/lib/hanami/port.rb +45 -0
  57. data/hanami-3.0.1/lib/hanami/prepare.rb +5 -0
  58. data/hanami-3.0.1/lib/hanami/provider/source.rb +16 -0
  59. data/hanami-3.0.1/lib/hanami/provider_registrar.rb +28 -0
  60. data/hanami-3.0.1/lib/hanami/providers/assets.rb +28 -0
  61. data/hanami-3.0.1/lib/hanami/providers/db/adapter.rb +75 -0
  62. data/hanami-3.0.1/lib/hanami/providers/db/adapters.rb +66 -0
  63. data/hanami-3.0.1/lib/hanami/providers/db/config.rb +44 -0
  64. data/hanami-3.0.1/lib/hanami/providers/db/gateway.rb +87 -0
  65. data/hanami-3.0.1/lib/hanami/providers/db/sql_adapter.rb +100 -0
  66. data/hanami-3.0.1/lib/hanami/providers/db.rb +325 -0
  67. data/hanami-3.0.1/lib/hanami/providers/db_logging.rb +19 -0
  68. data/hanami-3.0.1/lib/hanami/providers/i18n/backend.rb +373 -0
  69. data/hanami-3.0.1/lib/hanami/providers/i18n/locale/en.yml +57 -0
  70. data/hanami-3.0.1/lib/hanami/providers/i18n.rb +114 -0
  71. data/hanami-3.0.1/lib/hanami/providers/inflector.rb +17 -0
  72. data/hanami-3.0.1/lib/hanami/providers/logger.rb +41 -0
  73. data/hanami-3.0.1/lib/hanami/providers/mailers.rb +101 -0
  74. data/hanami-3.0.1/lib/hanami/providers/rack.rb +47 -0
  75. data/hanami-3.0.1/lib/hanami/providers/relations.rb +31 -0
  76. data/hanami-3.0.1/lib/hanami/providers/routes.rb +29 -0
  77. data/hanami-3.0.1/lib/hanami/rake_tasks.rb +54 -0
  78. data/hanami-3.0.1/lib/hanami/routes.rb +146 -0
  79. data/hanami-3.0.1/lib/hanami/settings/composite_store.rb +53 -0
  80. data/hanami-3.0.1/lib/hanami/settings/env_store.rb +32 -0
  81. data/hanami-3.0.1/lib/hanami/settings.rb +234 -0
  82. data/hanami-3.0.1/lib/hanami/setup.rb +6 -0
  83. data/hanami-3.0.1/lib/hanami/slice/router.rb +280 -0
  84. data/hanami-3.0.1/lib/hanami/slice/routes_helper.rb +37 -0
  85. data/hanami-3.0.1/lib/hanami/slice/routing/middleware/stack.rb +216 -0
  86. data/hanami-3.0.1/lib/hanami/slice/routing/resolver.rb +88 -0
  87. data/hanami-3.0.1/lib/hanami/slice/view_name_inferrer.rb +63 -0
  88. data/hanami-3.0.1/lib/hanami/slice.rb +1239 -0
  89. data/hanami-3.0.1/lib/hanami/slice_configurable.rb +72 -0
  90. data/hanami-3.0.1/lib/hanami/slice_name.rb +111 -0
  91. data/hanami-3.0.1/lib/hanami/slice_registrar.rb +215 -0
  92. data/hanami-3.0.1/lib/hanami/universal_logger.rb +250 -0
  93. data/hanami-3.0.1/lib/hanami/version.rb +45 -0
  94. data/hanami-3.0.1/lib/hanami/web/rack_logger.rb +126 -0
  95. data/hanami-3.0.1/lib/hanami/web/welcome.html.erb +584 -0
  96. data/hanami-3.0.1/lib/hanami/web/welcome.rb +46 -0
  97. data/hanami-3.0.1/lib/hanami.rb +276 -0
  98. data/piko-lite-box.gemspec +11 -0
  99. metadata +137 -0
@@ -0,0 +1,564 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+ require "pathname"
5
+ require "dry/configurable"
6
+ require "dry/inflector"
7
+
8
+ require_relative "constants"
9
+ require_relative "universal_logger"
10
+
11
+ module Hanami
12
+ # Hanami app config
13
+ #
14
+ # @since 2.0.0
15
+ class Config
16
+ include Dry::Configurable
17
+
18
+ # @!attribute [rw] root
19
+ # Sets the root for the app or slice.
20
+ #
21
+ # For the app, this defaults to `Dir.pwd`. For slices detected in `slices/` `config/slices/`,
22
+ # this defaults to `slices/[slice_name]/`.
23
+ #
24
+ # Accepts a string path and will return a `Pathname`.
25
+ #
26
+ # @return [Pathname]
27
+ #
28
+ # @api public
29
+ # @since 2.0.0
30
+ setting :root, constructor: ->(path) { Pathname(path) if path }
31
+
32
+ # @!attribute [rw] inflector
33
+ # Sets the app's inflector.
34
+ #
35
+ # This expects a `Dry::Inflector` (or compatible) inflector instance.
36
+ #
37
+ # To configure custom inflection rules without having to assign a whole inflector, see
38
+ # {#inflections}.
39
+ #
40
+ # @return [Dry::Inflector]
41
+ #
42
+ # @see #inflections
43
+ #
44
+ # @api public
45
+ # @since 2.0.0
46
+ setting :inflector, default: Dry::Inflector.new
47
+
48
+ # @!attribute [rw] settings_store
49
+ # Sets the store used to retrieve {Hanami::Settings} values.
50
+ #
51
+ # Defaults to an instance of {Hanami::Settings::EnvStore}.
52
+ #
53
+ # @return [#fetch]
54
+ #
55
+ # @see Hanami::Settings
56
+ # @see Hanami::Settings::EnvStore#fetch
57
+ #
58
+ # @api public
59
+ # @since 2.0.0
60
+ setting :settings_store, default: Hanami::Settings::EnvStore.new
61
+
62
+ # @!attribute [rw] slices
63
+ # Sets the slices to load when the app is preared or booted.
64
+ #
65
+ # Defaults to `nil`, which will load all slices. Set this to an array of slice names to load
66
+ # only those slices.
67
+ #
68
+ # This attribute is also populated from the `HANAMI_SLICES` environment variable.
69
+ #
70
+ # @example
71
+ # config.slices = ["admin", "search"]
72
+ #
73
+ # @example
74
+ # ENV["HANAMI_SLICES"] # => "admin,search"
75
+ # config.slices # => ["admin", "search"]
76
+ #
77
+ # @return [Array<String>, nil]
78
+ #
79
+ # @api public
80
+ # @since 2.0.0
81
+ setting :slices
82
+
83
+ # @!attribute [rw] shared_app_component_keys
84
+ # Sets the keys for the components to be imported from the app into all other slices.
85
+ #
86
+ # You should append items to this array, since the default shared components are essential for
87
+ # slices to operate within the app.
88
+ #
89
+ # @example
90
+ # config.shared_app_component_keys += ["shared_component_a", "shared_component_b"]
91
+ #
92
+ # @return [Array<String>]
93
+ #
94
+ # @api public
95
+ # @since 2.0.0
96
+ setting :shared_app_component_keys, default: %w[
97
+ inflector
98
+ logger
99
+ notifications
100
+ rack.monitor
101
+ routes
102
+ settings
103
+ ]
104
+
105
+ # @!attribute [rw] no_auto_register_paths
106
+ # Sets the paths to skip from container auto-registration.
107
+ #
108
+ # Paths are relative to `/app` or a slice root.
109
+ #
110
+ # Defaults to `["db", "entities", "relations", "structs"]`.
111
+ #
112
+ # @return [Array<String>] array of relative paths
113
+ #
114
+ # @api public
115
+ # @since 2.0.0
116
+ setting :no_auto_register_paths, default: [
117
+ "db",
118
+ "entities",
119
+ "relations",
120
+ "structs"
121
+ ]
122
+
123
+ # @!attribute [rw] no_memoize
124
+ # Sets the components that should not be memoized in the container.
125
+ #
126
+ # All auto-registered components are memoized by default, meaning each component is resolved
127
+ # only once, with the same instance returned on every subsequent resolution.
128
+ #
129
+ # Use this setting to opt specific components out of memoization. It accepts an array of key
130
+ # prefixes (strings) for the simple case, or a proc for full control. The proc receives a
131
+ # `Dry::System::Component` and should return `true` for components that should _not_ be
132
+ # memoized.
133
+ #
134
+ # Individual components can also opt out by adding a `# memoize: false` magic comment at the
135
+ # top of their source file.
136
+ #
137
+ # Defaults to `[]` (all components memoized).
138
+ #
139
+ # @example Opt out by key prefix
140
+ # config.no_memoize = ["workers", "jobs"]
141
+ #
142
+ # @example Opt out with a proc
143
+ # config.no_memoize = ->(component) {
144
+ # component.key.start_with?("workers")
145
+ # }
146
+ #
147
+ # @return [Array<String>, Proc]
148
+ #
149
+ # @api public
150
+ # @since 2.3.0
151
+ setting :no_memoize, default: []
152
+
153
+ # @!attribute [rw] base_url
154
+ # Sets the base URL for app's web server.
155
+ #
156
+ # This is passed to the {Slice::ClassMethods#router router} and used for generating links.
157
+ #
158
+ # Defaults to `"http://0.0.0.0:2300"`. String values passed are turned into `URI` instances.
159
+ #
160
+ # @return [URI]
161
+ #
162
+ # @see Slice::ClassMethods#router
163
+ #
164
+ # @api public
165
+ # @since 2.0.0
166
+ setting :base_url, default: "http://0.0.0.0:2300", constructor: ->(url) { URI(url) }
167
+
168
+ # @!attribute [rw] render_errors
169
+ # Sets whether to catch exceptions and render error pages.
170
+ #
171
+ # For HTML responses, these error pages are in `public/{404,500}.html`.
172
+ #
173
+ # Defaults to `true` in production mode, `false` in all others.
174
+ #
175
+ # @return [Boolean]
176
+ #
177
+ # @api public
178
+ # @since 2.1.0
179
+ setting :render_errors, default: false
180
+
181
+ # @!attribute [rw] render_detailed_errors
182
+ # Sets whether to catch exceptions and render detailed, interactive error pages.
183
+ #
184
+ # Requires the hanami-webconsole gem to be available.
185
+ #
186
+ # Defaults to `false` in production mode, `true` in all others.
187
+ #
188
+ # @return [Boolean]
189
+ #
190
+ # @api public
191
+ # @since 2.1.0
192
+ setting :render_detailed_errors, default: false
193
+
194
+ # @!attribute [rw] render_error_responses
195
+ # Sets a mapping of exception class names (as strings) to symbolic response status codes used
196
+ # for rendering error responses.
197
+ #
198
+ # The response status codes will be passed to `Rack::Utils.status_code`.
199
+ #
200
+ # In ordinary usage, you should not replace this hash. Instead, add keys and values for the
201
+ # errors you want handled.
202
+ #
203
+ # @example
204
+ # config.render_error_responses
205
+ # # => {"Hanami::Router::NotFoundError" => :not_found}
206
+ #
207
+ # config.render_error_responses["MyNotFoundError"] = :not_found
208
+ #
209
+ # @return [Hash{String => Symbol}]
210
+ #
211
+ # @see #render_errors
212
+ #
213
+ # @api public
214
+ # @since 2.1.0
215
+ setting :render_error_responses, default: Hash.new(:internal_server_error).merge!(
216
+ "Hanami::Router::NotAllowedError" => :not_found,
217
+ "Hanami::Router::NotFoundError" => :not_found
218
+ )
219
+
220
+ # @!attribute [rw] console
221
+ # Returns the app's console config
222
+ #
223
+ # @example
224
+ # config.console.engine # => :irb
225
+ #
226
+ # @return [Hanami::Config::Console]
227
+ #
228
+ # @api public
229
+ # @since 2.3.0
230
+ setting :console, default: Hanami::Config::Console.new
231
+
232
+ # Returns the app or slice's {Hanami::SliceName slice_name}.
233
+ #
234
+ # This is useful for default config values that depend on this name.
235
+ #
236
+ # @return [Hanami::SliceName]
237
+ #
238
+ # @api private
239
+ # @since 2.0.0
240
+ attr_reader :app_name
241
+
242
+ # Returns the app's environment.
243
+ #
244
+ # @example
245
+ # config.env # => :development
246
+ #
247
+ # @return [Symbol]
248
+ #
249
+ # @see #environment
250
+ #
251
+ # @api private
252
+ # @since 2.0.0
253
+ attr_reader :env
254
+
255
+ # Returns the app's actions config, or a null config if hanami-action is not bundled.
256
+ #
257
+ # @example When hanami-action is bundled
258
+ # config.actions.default_request_format # => :html
259
+ #
260
+ # @example When hanami-action is not bundled
261
+ # config.actions.default_request_format # => NoMethodError
262
+ #
263
+ # @return [Hanami::Config::Actions, Hanami::Config::NullConfig]
264
+ #
265
+ # @api public
266
+ # @since 2.0.0
267
+ attr_reader :actions
268
+
269
+ # Returns the app's db config, or a null config if hanami-db is not bundled.
270
+ #
271
+ # @example When hanami-db is bundled
272
+ # config.db.import_from_parent # => false
273
+ #
274
+ # @example When hanami-db is not bundle
275
+ # config.db.import_from_parent # => NoMethodError
276
+ #
277
+ # @return [Hanami::Config::DB, Hanami::Config::NullConfig]
278
+ #
279
+ # @api public
280
+ # @since 2.2.0
281
+ attr_reader :db
282
+
283
+ # Returns the app's i18n config, or a null config if i18n is not bundled.
284
+ #
285
+ # @example When i18n is bundled
286
+ # config.i18n.default_locale # => :en
287
+ #
288
+ # @example When i18n is not bundled
289
+ # config.i18n.default_locale # => NoMethodError
290
+ #
291
+ # @return [Hanami::Config::I18n, Hanami::Config::NullConfig]
292
+ #
293
+ # @api public
294
+ # @since 2.2.0
295
+ attr_reader :i18n
296
+
297
+ # Returns the app's middleware stack, or nil if hanami-router is not bundled.
298
+ #
299
+ # Use this to configure middleware that should apply to all routes.
300
+ #
301
+ # @example
302
+ # config.middleware.use :body_parser, :json
303
+ # config.middleware.use MyCustomMiddleware
304
+ #
305
+ # @return [Hanami::Slice::Routing::Middleware::Stack, nil]
306
+ #
307
+ # @api public
308
+ # @since 2.0.0
309
+ attr_reader :middleware
310
+
311
+ # @api private
312
+ # @since 2.0.0
313
+ alias_method :middleware_stack, :middleware
314
+
315
+ # Returns the app's router config, or a null config if hanami-router is not bundled.
316
+ #
317
+ # @example When hanami-router is bundled
318
+ # config.router.resolver # => Hanami::Slice::Routing::Resolver
319
+ #
320
+ # @example When hanami-router is not bundled
321
+ # config.router.resolver # => NoMethodError
322
+ #
323
+ # @return [Hanami::Config::Router, Hanami::Config::NullConfig]
324
+ #
325
+ # @api public
326
+ # @since 2.0.0
327
+ attr_reader :router
328
+
329
+ # Returns the app's views config, or a null config if hanami-view is not bundled.
330
+ #
331
+ # @example When hanami-view is bundled
332
+ # config.views.paths # => [...]
333
+ #
334
+ # @example When hanami-view is not bundled
335
+ # config.views.paths # => NoMethodError
336
+ #
337
+ # @return [Hanami::Config::Views, Hanami::Config::NullConfig]
338
+ #
339
+ # @api public
340
+ # @since 2.1.0
341
+ attr_reader :views
342
+
343
+ # Returns the app's views config, or a null config if hanami-view is not bundled.
344
+ #
345
+ # @example When hanami-view is bundled
346
+ # config.views.paths # => [...]
347
+ #
348
+ # @example When hanami-view is not bundled
349
+ # config.views.paths # => NoMethodError
350
+ #
351
+ # @return [Hanami::Config::Assets, Hanami::Config::NullConfig]
352
+ #
353
+ # @api public
354
+ # @since 2.1.0
355
+ attr_reader :assets
356
+
357
+ # @api private
358
+ # rubocop:disable Metrics/AbcSize
359
+ def initialize(app_name:, env:)
360
+ @app_name = app_name
361
+ @env = env
362
+
363
+ # Apply default values that are only knowable at initialize-time (vs require-time)
364
+ self.root = Dir.pwd
365
+ self.render_errors = (env == :production)
366
+ self.render_detailed_errors = (env == :development)
367
+ load_from_env
368
+
369
+ @actions = load_dependent_config("hanami-action") {
370
+ require_relative "config/actions"
371
+ Actions.new
372
+ }
373
+
374
+ @assets = load_dependent_config("hanami-assets") {
375
+ require_relative "config/assets"
376
+ Hanami::Config::Assets.new
377
+ }
378
+
379
+ @db = load_dependent_config("hanami-db") { DB.new }
380
+
381
+ @i18n = load_dependent_config("i18n") {
382
+ require_relative "config/i18n"
383
+ I18n.new
384
+ }
385
+
386
+ @logger = Config::Logger.new(env: env, app_name: app_name)
387
+
388
+ @middleware = load_dependent_config("hanami-router") {
389
+ require_relative "slice/routing/middleware/stack"
390
+ Slice::Routing::Middleware::Stack.new
391
+ }
392
+
393
+ @router = load_dependent_config("hanami-router") {
394
+ require_relative "config/router"
395
+ Router.new(self)
396
+ }
397
+
398
+ @views = load_dependent_config("hanami-view") {
399
+ require_relative "config/views"
400
+ Views.new
401
+ }
402
+
403
+ yield self if block_given?
404
+ end
405
+ # rubocop:enable Metrics/AbcSize
406
+
407
+ # @api private
408
+ def initialize_copy(source)
409
+ super
410
+
411
+ @app_name = app_name.dup
412
+
413
+ @actions = source.actions.dup
414
+ @assets = source.assets.dup
415
+ @db = source.db.dup
416
+ @i18n = source.i18n.dup
417
+ @logger = source.logger.dup
418
+ @middleware = source.middleware.dup
419
+ @router = source.router.dup.tap do |router|
420
+ router.instance_variable_set(:@base_config, self)
421
+ end
422
+ @views = source.views.dup
423
+ end
424
+ private :initialize_copy
425
+
426
+ # Finalizes the config.
427
+ #
428
+ # This is called when the app or slice is prepared. After this, no further changes to config can
429
+ # be made.
430
+ #
431
+ # @api private
432
+ def finalize!
433
+ # Finalize nested configs
434
+ assets.finalize!
435
+ actions.finalize!(self)
436
+ views.finalize!
437
+ logger.finalize!
438
+ router.finalize!
439
+
440
+ super
441
+ end
442
+
443
+ # Configures the app's custom inflections.
444
+ #
445
+ # You should call this one time only. Subsequent calls will override previously configured
446
+ # inflections.
447
+ #
448
+ # @example
449
+ # config.inflections do |inflections|
450
+ # inflections.acronym "WNBA"
451
+ # end
452
+ #
453
+ # @see https://dry-rb.org/gems/dry-inflector
454
+ #
455
+ # @return [Dry::Inflector] the configured inflector
456
+ #
457
+ # @api public
458
+ # @since 2.0.0
459
+ def inflections(&block)
460
+ self.inflector = Dry::Inflector.new(&block)
461
+ end
462
+
463
+ # Disabling this to permit distinct documentation for `#logger` vs `#logger=`
464
+ #
465
+ # rubocop:disable Style/TrivialAccessors
466
+
467
+ # Returns the logger config.
468
+ #
469
+ # Use this to configure various options for the default `Dry::Logger::Dispatcher` logger instance.
470
+ #
471
+ # @example
472
+ # config.logger.level = :debug
473
+ #
474
+ # @return [Hanami::Config::Logger]
475
+ #
476
+ # @see Hanami::Config::Logger
477
+ #
478
+ # @api public
479
+ # @since 2.0.0
480
+ def logger
481
+ @logger
482
+ end
483
+
484
+ # Sets the app's logger instance.
485
+ #
486
+ # This entirely replaces the default `Dry::Logger::Dispatcher` instance that would have been
487
+ # configured via {#logger}.
488
+ #
489
+ # The provided logger will be wrapped with {Hanami::UniversalLogger} if it doesn't support both
490
+ # keyword arguments and `#tagged` logging, ensuring compatibility with Hanami's logging
491
+ # interface.
492
+ #
493
+ # @see #logger_instance
494
+ # @see Hanami::UniversalLogger
495
+ #
496
+ # @api public
497
+ # @since 2.0.0
498
+ def logger=(logger_instance)
499
+ @logger_instance = Hanami::UniversalLogger[logger_instance]
500
+ end
501
+
502
+ # rubocop:enable Style/TrivialAccessors
503
+
504
+ # Returns the configured logger instance.
505
+ #
506
+ # Unless you've replaced the logger with {#logger=}, this returns a `Dry::Logger::Dispatcher` configured
507
+ # with the options configured through {#logger}.
508
+ #
509
+ # This configured logger is registered in all app and slice containers as `"logger"`. For
510
+ # typical usage, you should access the logger via this component, not directly from config.
511
+ #
512
+ # @example Accessing the logger component
513
+ # Hanami.app["logger"] # => #<Dry::Logger::Dispatcher>
514
+ #
515
+ # @example Injecting the logger as a dependency
516
+ # module MyApp
517
+ # class MyClass
518
+ # include Deps["logger"]
519
+ #
520
+ # def my_method
521
+ # logger.info("hello")
522
+ # end
523
+ # end
524
+ # end
525
+ #
526
+ # @return [Dry::Logger::Dispatcher]
527
+ #
528
+ # @see #logger
529
+ # @see Hanami::Config::Logger
530
+ #
531
+ # @api public
532
+ # @since 2.0.0
533
+ def logger_instance
534
+ @logger_instance || logger.instance
535
+ end
536
+
537
+ private
538
+
539
+ def load_from_env
540
+ self.slices = ENV["HANAMI_SLICES"]&.split(",")&.map(&:strip)
541
+ end
542
+
543
+ def load_dependent_config(gem_name)
544
+ if Hanami.bundled?(gem_name)
545
+ yield
546
+ else
547
+ require_relative "config/null_config"
548
+ NullConfig.new
549
+ end
550
+ end
551
+
552
+ def method_missing(name, *args, &block)
553
+ if config.respond_to?(name)
554
+ config.public_send(name, *args, &block)
555
+ else
556
+ super
557
+ end
558
+ end
559
+
560
+ def respond_to_missing?(name, _include_all = false)
561
+ config.respond_to?(name) || super
562
+ end
563
+ end
564
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ # @api private
5
+ CONTAINER_KEY_DELIMITER = "."
6
+ private_constant :CONTAINER_KEY_DELIMITER
7
+
8
+ # @api private
9
+ MODULE_DELIMITER = "::"
10
+ private_constant :MODULE_DELIMITER
11
+
12
+ # @api private
13
+ PATH_DELIMITER = "/"
14
+ private_constant :PATH_DELIMITER
15
+
16
+ # @api private
17
+ APP_PATH = "config/app.rb"
18
+ private_constant :APP_PATH
19
+
20
+ # @api private
21
+ CONFIG_DIR = "config"
22
+ private_constant :CONFIG_DIR
23
+
24
+ # @api private
25
+ APP_DIR = "app"
26
+ private_constant :APP_DIR
27
+
28
+ # @api private
29
+ LIB_DIR = "lib"
30
+ private_constant :LIB_DIR
31
+
32
+ # @api private
33
+ SLICES_DIR = "slices"
34
+ private_constant :SLICES_DIR
35
+
36
+ # @api private
37
+ ROUTES_PATH = File.join(CONFIG_DIR, "routes")
38
+ private_constant :ROUTES_PATH
39
+
40
+ # @api private
41
+ ROUTES_CLASS_NAME = "Routes"
42
+ private_constant :ROUTES_CLASS_NAME
43
+
44
+ # @api private
45
+ SETTINGS_PATH = File.join(CONFIG_DIR, "settings")
46
+ private_constant :SETTINGS_PATH
47
+
48
+ # @api private
49
+ SETTINGS_CLASS_NAME = "Settings"
50
+ private_constant :SETTINGS_CLASS_NAME
51
+
52
+ # @api private
53
+ RB_EXT = ".rb"
54
+ private_constant :RB_EXT
55
+
56
+ # @api private
57
+ RB_EXT_REGEXP = %r{.rb$}
58
+ private_constant :RB_EXT_REGEXP
59
+
60
+ # @api private
61
+ CONTENT_SECURITY_POLICY_NONCE_REQUEST_KEY = "hanami.content_security_policy_nonce"
62
+ end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ module Env
5
+ # @since 2.0.1
6
+ # @api private
7
+ @_loaded = false
8
+
9
+ # Uses [dotenv](https://github.com/bkeepers/dotenv) (if available) to populate `ENV` from
10
+ # various `.env` files.
11
+ #
12
+ # For a given `HANAMI_ENV` environment, the `.env` files are looked up in the following order:
13
+ #
14
+ # - .env.{environment}.local
15
+ # - .env.local (unless the environment is `test`)
16
+ # - .env.{environment}
17
+ # - .env
18
+ #
19
+ # If dotenv is unavailable, the method exits and does nothing.
20
+ #
21
+ # @since 2.0.1
22
+ # @api private
23
+ def self.load(env = Hanami.env)
24
+ return unless Hanami.bundled?("dotenv")
25
+ return if loaded?
26
+
27
+ dotenv_files = [
28
+ ".env.#{env}.local",
29
+ (".env.local" unless env == :test),
30
+ ".env.#{env}",
31
+ ".env"
32
+ ].compact
33
+
34
+ require "dotenv"
35
+ Dotenv.load(*dotenv_files)
36
+
37
+ loaded!
38
+ end
39
+
40
+ # @since 2.0.1
41
+ # @api private
42
+ def self.loaded?
43
+ @_loaded
44
+ end
45
+
46
+ # @since 2.0.1
47
+ # @api private
48
+ def self.loaded!
49
+ @_loaded = true
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Hanami
4
+ # Base class for all Hanami errors.
5
+ #
6
+ # @api public
7
+ # @since 2.0.0
8
+ Error = Class.new(StandardError)
9
+
10
+ # Error raised when {Hanami::App} fails to load.
11
+ #
12
+ # @api public
13
+ # @since 2.0.0
14
+ AppLoadError = Class.new(Error)
15
+
16
+ # Error raised when an {Hanami::Slice} fails to load.
17
+ #
18
+ # @api public
19
+ # @since 2.0.0
20
+ SliceLoadError = Class.new(Error)
21
+
22
+ # Error raised when an individual component fails to load.
23
+ #
24
+ # @api public
25
+ # @since 2.0.0
26
+ ComponentLoadError = Class.new(Error)
27
+
28
+ # Error raised when there are no routes defined.
29
+ #
30
+ # @api public
31
+ # @since 2.4.0
32
+ NoRoutesDefinedError = Class.new(Error)
33
+
34
+ # Error raised when unsupported middleware configuration is given.
35
+ #
36
+ # @see Hanami::Slice::Routing::Middleware::Stack#use
37
+ #
38
+ # @api public
39
+ # @since 2.0.0
40
+ UnsupportedMiddlewareSpecError = Class.new(Error)
41
+ end