hanami 2.0.0.alpha7.1 → 2.0.0.alpha8
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 +15 -0
- data/lib/hanami/application/action/slice_configured_action.rb +103 -0
- data/lib/hanami/application/action.rb +72 -0
- data/lib/hanami/application/view/context.rb +95 -0
- data/lib/hanami/application/view/slice_configured_context.rb +71 -0
- data/lib/hanami/application/view/slice_configured_view.rb +101 -0
- data/lib/hanami/application/view.rb +24 -0
- data/lib/hanami/application/view_name_inferrer.rb +63 -0
- data/lib/hanami/application.rb +22 -48
- data/lib/hanami/configuration/actions/content_security_policy.rb +118 -0
- data/lib/hanami/configuration/actions/cookies.rb +29 -0
- data/lib/hanami/configuration/actions/sessions.rb +46 -0
- data/lib/hanami/configuration/actions.rb +16 -11
- data/lib/hanami/configuration/logger.rb +11 -8
- data/lib/hanami/configuration/views.rb +81 -0
- data/lib/hanami/configuration.rb +25 -40
- data/lib/hanami/constants.rb +6 -0
- data/lib/hanami/errors.rb +3 -0
- data/lib/hanami/slice.rb +11 -14
- data/lib/hanami/slice_configurable.rb +75 -0
- data/lib/hanami/slice_name.rb +111 -0
- data/lib/hanami/version.rb +1 -1
- metadata +16 -4
- data/lib/hanami/boot/source_dirs.rb +0 -44
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "constants"
|
|
4
|
+
|
|
5
|
+
module Hanami
|
|
6
|
+
# Represents the name of an {Application} or {Slice}.
|
|
7
|
+
#
|
|
8
|
+
# @see Application::ClassMethods#application_name
|
|
9
|
+
# @see Slice::ClassMethods#slice_name
|
|
10
|
+
#
|
|
11
|
+
# @api public
|
|
12
|
+
# @since 2.0.0
|
|
13
|
+
class SliceName
|
|
14
|
+
# Returns a new SliceName for the slice or application.
|
|
15
|
+
#
|
|
16
|
+
# You must provide an inflector for the manipulation of the name into various formats.
|
|
17
|
+
# This should be given in the form of a Proc that returns the inflector when called.
|
|
18
|
+
# The reason for this is that the inflector may be replaced by the user during the
|
|
19
|
+
# application configuration phase, so the proc should ensure that the current instance
|
|
20
|
+
# of the inflector is returned whenever needed.
|
|
21
|
+
#
|
|
22
|
+
# @param slice [#name] the slice or application object
|
|
23
|
+
# @param inflector [Proc] Proc returning the application's inflector when called
|
|
24
|
+
#
|
|
25
|
+
# @api private
|
|
26
|
+
def initialize(slice, inflector:)
|
|
27
|
+
@slice = slice
|
|
28
|
+
@inflector = inflector
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Returns the name of the slice as a downcased, underscored string.
|
|
32
|
+
#
|
|
33
|
+
# This is considered the canonical name of the slice.
|
|
34
|
+
#
|
|
35
|
+
# @example
|
|
36
|
+
# slice_name.name # => "main"
|
|
37
|
+
#
|
|
38
|
+
# @return [String] the slice name
|
|
39
|
+
#
|
|
40
|
+
# @api public
|
|
41
|
+
# @since 2.0.0
|
|
42
|
+
def name
|
|
43
|
+
inflector.underscore(namespace_name)
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# @api public
|
|
47
|
+
# @since 2.0.0
|
|
48
|
+
alias_method :path, :name
|
|
49
|
+
|
|
50
|
+
# Returns the name of the slice's module namespace.
|
|
51
|
+
#
|
|
52
|
+
# @example
|
|
53
|
+
# slice_name.namespace_name # => "Main"
|
|
54
|
+
#
|
|
55
|
+
# @return [String] the namespace name
|
|
56
|
+
#
|
|
57
|
+
# @api public
|
|
58
|
+
# @since 2.0.0
|
|
59
|
+
def namespace_name
|
|
60
|
+
slice_name.split(MODULE_DELIMITER)[0..-2].join(MODULE_DELIMITER)
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# Returns the constant for the slice's module namespace.
|
|
64
|
+
#
|
|
65
|
+
# @example
|
|
66
|
+
# slice_name.namespace_const # => Main
|
|
67
|
+
#
|
|
68
|
+
# @return [Module] the namespace module constant
|
|
69
|
+
#
|
|
70
|
+
# @api public
|
|
71
|
+
# @since 2.0.0
|
|
72
|
+
def namespace_const
|
|
73
|
+
inflector.constantize(namespace_name)
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# @api public
|
|
77
|
+
# @since 2.0.0
|
|
78
|
+
alias_method :namespace, :namespace_const
|
|
79
|
+
|
|
80
|
+
# @api public
|
|
81
|
+
# @since 2.0.0
|
|
82
|
+
alias_method :to_s, :name
|
|
83
|
+
|
|
84
|
+
# Returns the name of a slice as a downcased, underscored symbol.
|
|
85
|
+
#
|
|
86
|
+
# @example
|
|
87
|
+
# slice_name.name # => :main
|
|
88
|
+
#
|
|
89
|
+
# @return [Symbol] the slice name
|
|
90
|
+
#
|
|
91
|
+
# @see name, to_s
|
|
92
|
+
#
|
|
93
|
+
# @api public
|
|
94
|
+
# @since 2.0.0
|
|
95
|
+
def to_sym
|
|
96
|
+
name.to_sym
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
private
|
|
100
|
+
|
|
101
|
+
def slice_name
|
|
102
|
+
@slice.name
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# The inflector is callable to allow for it to be configured/replaced after this
|
|
106
|
+
# object has been initialized
|
|
107
|
+
def inflector
|
|
108
|
+
@inflector.()
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
data/lib/hanami/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: hanami
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.0.0.
|
|
4
|
+
version: 2.0.0.alpha8
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Luca Guidi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-
|
|
11
|
+
date: 2022-05-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -217,6 +217,8 @@ files:
|
|
|
217
217
|
- hanami.gemspec
|
|
218
218
|
- lib/hanami.rb
|
|
219
219
|
- lib/hanami/application.rb
|
|
220
|
+
- lib/hanami/application/action.rb
|
|
221
|
+
- lib/hanami/application/action/slice_configured_action.rb
|
|
220
222
|
- lib/hanami/application/container/providers/inflector.rb
|
|
221
223
|
- lib/hanami/application/container/providers/logger.rb
|
|
222
224
|
- lib/hanami/application/container/providers/rack_logger.rb
|
|
@@ -234,10 +236,14 @@ files:
|
|
|
234
236
|
- lib/hanami/application/settings.rb
|
|
235
237
|
- lib/hanami/application/settings/dotenv_store.rb
|
|
236
238
|
- lib/hanami/application/slice_registrar.rb
|
|
239
|
+
- lib/hanami/application/view.rb
|
|
240
|
+
- lib/hanami/application/view/context.rb
|
|
241
|
+
- lib/hanami/application/view/slice_configured_context.rb
|
|
242
|
+
- lib/hanami/application/view/slice_configured_view.rb
|
|
243
|
+
- lib/hanami/application/view_name_inferrer.rb
|
|
237
244
|
- lib/hanami/assets/application_configuration.rb
|
|
238
245
|
- lib/hanami/assets/configuration.rb
|
|
239
246
|
- lib/hanami/boot.rb
|
|
240
|
-
- lib/hanami/boot/source_dirs.rb
|
|
241
247
|
- lib/hanami/cli/application/cli.rb
|
|
242
248
|
- lib/hanami/cli/application/command.rb
|
|
243
249
|
- lib/hanami/cli/application/commands.rb
|
|
@@ -248,18 +254,24 @@ files:
|
|
|
248
254
|
- lib/hanami/cli/commands/server.rb
|
|
249
255
|
- lib/hanami/configuration.rb
|
|
250
256
|
- lib/hanami/configuration/actions.rb
|
|
257
|
+
- lib/hanami/configuration/actions/content_security_policy.rb
|
|
258
|
+
- lib/hanami/configuration/actions/cookies.rb
|
|
259
|
+
- lib/hanami/configuration/actions/sessions.rb
|
|
251
260
|
- lib/hanami/configuration/logger.rb
|
|
252
261
|
- lib/hanami/configuration/middleware.rb
|
|
253
262
|
- lib/hanami/configuration/null_configuration.rb
|
|
254
263
|
- lib/hanami/configuration/router.rb
|
|
255
264
|
- lib/hanami/configuration/sessions.rb
|
|
256
265
|
- lib/hanami/configuration/source_dirs.rb
|
|
266
|
+
- lib/hanami/configuration/views.rb
|
|
257
267
|
- lib/hanami/constants.rb
|
|
258
268
|
- lib/hanami/errors.rb
|
|
259
269
|
- lib/hanami/prepare.rb
|
|
260
270
|
- lib/hanami/server.rb
|
|
261
271
|
- lib/hanami/setup.rb
|
|
262
272
|
- lib/hanami/slice.rb
|
|
273
|
+
- lib/hanami/slice_configurable.rb
|
|
274
|
+
- lib/hanami/slice_name.rb
|
|
263
275
|
- lib/hanami/version.rb
|
|
264
276
|
- lib/hanami/web/rack_logger.rb
|
|
265
277
|
homepage: http://hanamirb.org
|
|
@@ -283,7 +295,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
283
295
|
- !ruby/object:Gem::Version
|
|
284
296
|
version: 1.3.1
|
|
285
297
|
requirements: []
|
|
286
|
-
rubygems_version: 3.3.
|
|
298
|
+
rubygems_version: 3.3.7
|
|
287
299
|
signing_key:
|
|
288
300
|
specification_version: 4
|
|
289
301
|
summary: The web, with simplicity
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
module Hanami
|
|
2
|
-
module Boot
|
|
3
|
-
module SourceDirs
|
|
4
|
-
def self.setup_component_dir!(component_dir, slice, container)
|
|
5
|
-
# TODO: this `== "lib"` check should be codified into a method somewhere
|
|
6
|
-
if component_dir.path == "lib"
|
|
7
|
-
# Expect component files in the root of the lib
|
|
8
|
-
# component dir to define classes inside the slice's namespace.
|
|
9
|
-
#
|
|
10
|
-
# e.g. "lib/foo.rb" should define SliceNamespace::Foo, and will be
|
|
11
|
-
# registered as "foo"
|
|
12
|
-
component_dir.namespaces.root(key: nil, const: slice.namespace_path)
|
|
13
|
-
|
|
14
|
-
slice.application.autoloader.push_dir(slice.root.join("lib"), namespace: slice.namespace)
|
|
15
|
-
|
|
16
|
-
container.config.component_dirs.add(component_dir)
|
|
17
|
-
else
|
|
18
|
-
# Expect component files in the root of these component dirs to define
|
|
19
|
-
# classes inside a namespace matching the dir.
|
|
20
|
-
#
|
|
21
|
-
# e.g. "actions/foo.rb" should define SliceNamespace::Actions::Foo, and
|
|
22
|
-
# will be registered as "actions.foo"
|
|
23
|
-
|
|
24
|
-
dir_namespace_path = File.join(slice.namespace_path, component_dir.path)
|
|
25
|
-
|
|
26
|
-
autoloader_namespace = begin
|
|
27
|
-
slice.inflector.constantize(slice.inflector.camelize(dir_namespace_path))
|
|
28
|
-
rescue NameError
|
|
29
|
-
slice.namespace.const_set(slice.inflector.camelize(component_dir.path), Module.new)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
# TODO: do we need to do something special to clear out any previously configured root namespace here?
|
|
33
|
-
component_dir.namespaces.root(const: dir_namespace_path, key: component_dir.path) # TODO: do we need to swap path delimiters for key delimiters here?
|
|
34
|
-
container.config.component_dirs.add(component_dir)
|
|
35
|
-
|
|
36
|
-
slice.application.autoloader.push_dir(
|
|
37
|
-
slice.root.join(component_dir.path),
|
|
38
|
-
namespace: autoloader_namespace
|
|
39
|
-
)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|