hanami 2.0.0.alpha7.1 → 2.0.0.beta1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +457 -237
- data/FEATURES.md +30 -9
- data/README.md +1 -3
- data/hanami.gemspec +21 -11
- data/lib/hanami/app.rb +141 -0
- data/lib/hanami/assets/application_configuration.rb +10 -4
- 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 +23 -12
- data/lib/hanami/configuration/logger.rb +13 -10
- data/lib/hanami/configuration/router.rb +2 -6
- data/lib/hanami/configuration/sessions.rb +1 -1
- data/lib/hanami/configuration/views.rb +86 -0
- data/lib/hanami/configuration.rb +139 -82
- data/lib/hanami/constants.rb +30 -2
- data/lib/hanami/errors.rb +4 -1
- data/lib/hanami/extensions/action/slice_configured_action.rb +103 -0
- data/lib/hanami/extensions/action.rb +79 -0
- data/lib/hanami/extensions/view/context.rb +106 -0
- data/lib/hanami/extensions/view/slice_configured_context.rb +71 -0
- data/lib/hanami/extensions/view/slice_configured_view.rb +107 -0
- data/lib/hanami/extensions/view.rb +33 -0
- data/lib/hanami/extensions.rb +10 -0
- data/lib/hanami/providers/inflector.rb +13 -0
- data/lib/hanami/providers/logger.rb +13 -0
- data/lib/hanami/providers/rack.rb +27 -0
- data/lib/hanami/providers/routes.rb +33 -0
- data/lib/hanami/providers/settings.rb +23 -0
- data/lib/hanami/rake_tasks.rb +61 -0
- data/lib/hanami/routes.rb +51 -0
- data/lib/hanami/server.rb +1 -1
- data/lib/hanami/settings/dotenv_store.rb +58 -0
- data/lib/hanami/settings.rb +90 -0
- data/lib/hanami/setup.rb +4 -2
- data/lib/hanami/{application → slice}/router.rb +18 -13
- data/lib/hanami/slice/routes_helper.rb +37 -0
- data/lib/hanami/{application → slice}/routing/middleware/stack.rb +43 -5
- data/lib/hanami/slice/routing/resolver.rb +97 -0
- data/lib/hanami/slice/view_name_inferrer.rb +63 -0
- data/lib/hanami/slice.rb +252 -82
- data/lib/hanami/slice_configurable.rb +62 -0
- data/lib/hanami/slice_name.rb +111 -0
- data/lib/hanami/slice_registrar.rb +119 -0
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami/web/rack_logger.rb +1 -1
- data/lib/hanami.rb +34 -26
- data/spec/integration/application_middleware_stack_spec.rb +84 -0
- data/spec/integration/assets/cdn_spec.rb +48 -0
- data/spec/integration/assets/fingerprint_spec.rb +42 -0
- data/spec/integration/assets/helpers_spec.rb +50 -0
- data/spec/integration/assets/serve_spec.rb +70 -0
- data/spec/integration/assets/subresource_integrity_spec.rb +54 -0
- data/spec/integration/body_parsers_spec.rb +50 -0
- data/spec/integration/cli/assets/precompile_spec.rb +147 -0
- data/spec/integration/cli/assets_spec.rb +14 -0
- data/spec/integration/cli/console_spec.rb +105 -0
- data/spec/integration/cli/db/apply_spec.rb +74 -0
- data/spec/integration/cli/db/console_spec.rb +40 -0
- data/spec/integration/cli/db/create_spec.rb +50 -0
- data/spec/integration/cli/db/drop_spec.rb +54 -0
- data/spec/integration/cli/db/migrate_spec.rb +108 -0
- data/spec/integration/cli/db/prepare_spec.rb +36 -0
- data/spec/integration/cli/db/rollback_spec.rb +96 -0
- data/spec/integration/cli/db/version_spec.rb +38 -0
- data/spec/integration/cli/db_spec.rb +21 -0
- data/spec/integration/cli/destroy/action_spec.rb +143 -0
- data/spec/integration/cli/destroy/app_spec.rb +118 -0
- data/spec/integration/cli/destroy/mailer_spec.rb +74 -0
- data/spec/integration/cli/destroy/migration_spec.rb +70 -0
- data/spec/integration/cli/destroy/model_spec.rb +113 -0
- data/spec/integration/cli/destroy_spec.rb +18 -0
- data/spec/integration/cli/generate/action_spec.rb +469 -0
- data/spec/integration/cli/generate/app_spec.rb +215 -0
- data/spec/integration/cli/generate/mailer_spec.rb +189 -0
- data/spec/integration/cli/generate/migration_spec.rb +72 -0
- data/spec/integration/cli/generate/model_spec.rb +290 -0
- data/spec/integration/cli/generate/secret_spec.rb +56 -0
- data/spec/integration/cli/generate_spec.rb +19 -0
- data/spec/integration/cli/new/database_spec.rb +235 -0
- data/spec/integration/cli/new/hanami_head_spec.rb +27 -0
- data/spec/integration/cli/new/template_spec.rb +118 -0
- data/spec/integration/cli/new/test_spec.rb +274 -0
- data/spec/integration/cli/new_spec.rb +970 -0
- data/spec/integration/cli/plugins_spec.rb +39 -0
- data/spec/integration/cli/routes_spec.rb +49 -0
- data/spec/integration/cli/server_spec.rb +626 -0
- data/spec/integration/cli/version_spec.rb +85 -0
- data/spec/integration/early_hints_spec.rb +35 -0
- data/spec/integration/handle_exceptions_spec.rb +244 -0
- data/spec/integration/head_spec.rb +89 -0
- data/spec/integration/http_headers_spec.rb +29 -0
- data/spec/integration/mailer_spec.rb +32 -0
- data/spec/integration/middleware_spec.rb +81 -0
- data/spec/integration/mount_applications_spec.rb +88 -0
- data/spec/integration/project_initializers_spec.rb +40 -0
- data/spec/integration/rackup_spec.rb +35 -0
- data/spec/integration/rake/with_minitest_spec.rb +67 -0
- data/spec/integration/rake/with_rspec_spec.rb +69 -0
- data/spec/integration/routing_helpers_spec.rb +61 -0
- data/spec/integration/security/content_security_policy_spec.rb +46 -0
- data/spec/integration/security/csrf_protection_spec.rb +42 -0
- data/spec/integration/security/force_ssl_spec.rb +29 -0
- data/spec/integration/security/x_content_type_options_spec.rb +46 -0
- data/spec/integration/security/x_frame_options_spec.rb +46 -0
- data/spec/integration/security/x_xss_protection_spec.rb +46 -0
- data/spec/integration/send_file_spec.rb +51 -0
- data/spec/integration/sessions_spec.rb +247 -0
- data/spec/integration/static_middleware_spec.rb +21 -0
- data/spec/integration/streaming_spec.rb +41 -0
- data/spec/integration/unsafe_send_file_spec.rb +52 -0
- data/spec/isolation/hanami/application/already_configured_spec.rb +19 -0
- data/spec/isolation/hanami/application/inherit_anonymous_class_spec.rb +10 -0
- data/spec/isolation/hanami/application/inherit_concrete_class_spec.rb +14 -0
- data/spec/isolation/hanami/application/not_configured_spec.rb +9 -0
- data/spec/isolation/hanami/application/routes/configured_spec.rb +44 -0
- data/spec/isolation/hanami/application/routes/not_configured_spec.rb +16 -0
- data/spec/isolation/hanami/boot/success_spec.rb +50 -0
- data/spec/new_integration/action/configuration_spec.rb +26 -0
- data/spec/new_integration/action/cookies_spec.rb +58 -0
- data/spec/new_integration/action/csrf_protection_spec.rb +54 -0
- data/spec/new_integration/action/routes_spec.rb +73 -0
- data/spec/new_integration/action/sessions_spec.rb +50 -0
- data/spec/new_integration/action/view_integration_spec.rb +165 -0
- data/spec/new_integration/action/view_rendering/automatic_rendering_spec.rb +247 -0
- data/spec/new_integration/action/view_rendering/paired_view_inference_spec.rb +115 -0
- data/spec/new_integration/action/view_rendering_spec.rb +107 -0
- data/spec/new_integration/code_loading/loading_from_app_spec.rb +152 -0
- data/spec/new_integration/code_loading/loading_from_slice_spec.rb +165 -0
- data/spec/new_integration/container/application_routes_helper_spec.rb +48 -0
- data/spec/new_integration/container/auto_injection_spec.rb +53 -0
- data/spec/new_integration/container/auto_registration_spec.rb +86 -0
- data/spec/new_integration/container/autoloader_spec.rb +80 -0
- data/spec/new_integration/container/imports_spec.rb +253 -0
- data/spec/new_integration/container/prepare_container_spec.rb +123 -0
- data/spec/new_integration/container/shutdown_spec.rb +91 -0
- data/spec/new_integration/container/standard_bootable_components_spec.rb +124 -0
- data/spec/new_integration/rack_app/middleware_spec.rb +215 -0
- data/spec/new_integration/rack_app/non_booted_rack_app_spec.rb +105 -0
- data/spec/new_integration/rack_app/rack_app_spec.rb +524 -0
- data/spec/new_integration/settings_spec.rb +115 -0
- data/spec/new_integration/slices/external_slice_spec.rb +92 -0
- data/spec/new_integration/slices/slice_configuration_spec.rb +40 -0
- data/spec/new_integration/slices/slice_routing_spec.rb +226 -0
- data/spec/new_integration/slices/slice_settings_spec.rb +141 -0
- data/spec/new_integration/slices_spec.rb +101 -0
- data/spec/new_integration/view/configuration_spec.rb +49 -0
- data/spec/new_integration/view/context/assets_spec.rb +67 -0
- data/spec/new_integration/view/context/inflector_spec.rb +48 -0
- data/spec/new_integration/view/context/request_spec.rb +61 -0
- data/spec/new_integration/view/context/routes_spec.rb +86 -0
- data/spec/new_integration/view/context/settings_spec.rb +50 -0
- data/spec/new_integration/view/inflector_spec.rb +57 -0
- data/spec/new_integration/view/part_namespace_spec.rb +96 -0
- data/spec/new_integration/view/path_spec.rb +56 -0
- data/spec/new_integration/view/template_spec.rb +68 -0
- data/spec/new_integration/view/views_spec.rb +103 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/app_integration.rb +91 -0
- data/spec/support/coverage.rb +1 -0
- data/spec/support/fixtures/hanami-plugin/Gemfile +8 -0
- data/spec/support/fixtures/hanami-plugin/README.md +35 -0
- data/spec/support/fixtures/hanami-plugin/Rakefile +4 -0
- data/spec/support/fixtures/hanami-plugin/bin/console +15 -0
- data/spec/support/fixtures/hanami-plugin/bin/setup +8 -0
- data/spec/support/fixtures/hanami-plugin/hanami-plugin.gemspec +28 -0
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/cli.rb +19 -0
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin/version.rb +7 -0
- data/spec/support/fixtures/hanami-plugin/lib/hanami/plugin.rb +8 -0
- data/spec/support/rspec.rb +27 -0
- data/spec/support/shared_examples/cli/generate/app.rb +494 -0
- data/spec/support/shared_examples/cli/generate/migration.rb +32 -0
- data/spec/support/shared_examples/cli/generate/model.rb +81 -0
- data/spec/support/shared_examples/cli/new.rb +97 -0
- data/spec/unit/hanami/configuration/actions/content_security_policy_spec.rb +102 -0
- data/spec/unit/hanami/configuration/actions/cookies_spec.rb +46 -0
- data/spec/unit/hanami/configuration/actions/csrf_protection_spec.rb +57 -0
- data/spec/unit/hanami/configuration/actions/default_values_spec.rb +52 -0
- data/spec/unit/hanami/configuration/actions/sessions_spec.rb +50 -0
- data/spec/unit/hanami/configuration/actions_spec.rb +78 -0
- data/spec/unit/hanami/configuration/base_url_spec.rb +25 -0
- data/spec/unit/hanami/configuration/inflector_spec.rb +35 -0
- data/spec/unit/hanami/configuration/logger_spec.rb +203 -0
- data/spec/unit/hanami/configuration/views_spec.rb +120 -0
- data/spec/unit/hanami/configuration_spec.rb +43 -0
- data/spec/unit/hanami/env_spec.rb +54 -0
- data/spec/unit/hanami/routes_spec.rb +25 -0
- data/spec/unit/hanami/settings/dotenv_store_spec.rb +119 -0
- data/spec/unit/hanami/settings_spec.rb +56 -0
- data/spec/unit/hanami/slice_configurable_spec.rb +104 -0
- data/spec/unit/hanami/slice_name_spec.rb +47 -0
- data/spec/unit/hanami/slice_spec.rb +17 -0
- data/spec/unit/hanami/version_spec.rb +7 -0
- data/spec/unit/hanami/web/rack_logger_spec.rb +78 -0
- metadata +363 -55
- data/lib/hanami/application/container/providers/inflector.rb +0 -7
- data/lib/hanami/application/container/providers/logger.rb +0 -7
- data/lib/hanami/application/container/providers/rack_logger.rb +0 -15
- data/lib/hanami/application/container/providers/rack_monitor.rb +0 -12
- data/lib/hanami/application/container/providers/routes_helper.rb +0 -9
- data/lib/hanami/application/container/providers/settings.rb +0 -7
- data/lib/hanami/application/routes.rb +0 -55
- data/lib/hanami/application/routes_helper.rb +0 -34
- data/lib/hanami/application/routing/resolver/node.rb +0 -50
- data/lib/hanami/application/routing/resolver/trie.rb +0 -59
- data/lib/hanami/application/routing/resolver.rb +0 -87
- data/lib/hanami/application/routing/router.rb +0 -36
- data/lib/hanami/application/settings/dotenv_store.rb +0 -60
- data/lib/hanami/application/settings.rb +0 -93
- data/lib/hanami/application/slice_registrar.rb +0 -106
- data/lib/hanami/application.rb +0 -299
- data/lib/hanami/boot/source_dirs.rb +0 -44
- data/lib/hanami/cli/application/cli.rb +0 -40
- data/lib/hanami/cli/application/command.rb +0 -47
- data/lib/hanami/cli/application/commands/console.rb +0 -81
- data/lib/hanami/cli/application/commands.rb +0 -16
- data/lib/hanami/cli/base_command.rb +0 -48
- data/lib/hanami/cli/commands/command.rb +0 -171
- data/lib/hanami/cli/commands/server.rb +0 -88
- data/lib/hanami/cli/commands.rb +0 -65
- data/lib/hanami/configuration/middleware.rb +0 -20
- data/lib/hanami/configuration/source_dirs.rb +0 -42
data/lib/hanami/application.rb
DELETED
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "dry/system/container"
|
|
4
|
-
require "hanami/configuration"
|
|
5
|
-
require "pathname"
|
|
6
|
-
require "rack"
|
|
7
|
-
require "zeitwerk"
|
|
8
|
-
require_relative "constants"
|
|
9
|
-
require_relative "slice"
|
|
10
|
-
require_relative "application/slice_registrar"
|
|
11
|
-
|
|
12
|
-
module Hanami
|
|
13
|
-
# Hanami application class
|
|
14
|
-
#
|
|
15
|
-
# @since 2.0.0
|
|
16
|
-
class Application
|
|
17
|
-
@_mutex = Mutex.new
|
|
18
|
-
|
|
19
|
-
class << self
|
|
20
|
-
def inherited(klass)
|
|
21
|
-
super
|
|
22
|
-
@_mutex.synchronize do
|
|
23
|
-
klass.class_eval do
|
|
24
|
-
@_mutex = Mutex.new
|
|
25
|
-
@_configuration = Hanami::Configuration.new(application_name: name, env: Hanami.env)
|
|
26
|
-
@autoloader = Zeitwerk::Loader.new
|
|
27
|
-
@container = Class.new(Dry::System::Container)
|
|
28
|
-
|
|
29
|
-
extend ClassMethods
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
klass.send :prepare_base_load_path
|
|
33
|
-
|
|
34
|
-
Hanami.application = klass
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
# Application class interface
|
|
40
|
-
#
|
|
41
|
-
# rubocop:disable Metrics/ModuleLength
|
|
42
|
-
module ClassMethods
|
|
43
|
-
attr_reader :autoloader, :container
|
|
44
|
-
|
|
45
|
-
def self.extended(klass)
|
|
46
|
-
klass.class_eval do
|
|
47
|
-
@prepared = @booted = false
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def configuration
|
|
52
|
-
@_configuration
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
alias_method :config, :configuration
|
|
56
|
-
|
|
57
|
-
def prepare(provider_name = nil)
|
|
58
|
-
container.prepare(provider_name) and return self if provider_name
|
|
59
|
-
|
|
60
|
-
return self if prepared?
|
|
61
|
-
|
|
62
|
-
configuration.finalize!
|
|
63
|
-
|
|
64
|
-
prepare_all
|
|
65
|
-
|
|
66
|
-
@prepared = true
|
|
67
|
-
self
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def boot(&block)
|
|
71
|
-
return self if booted?
|
|
72
|
-
|
|
73
|
-
prepare
|
|
74
|
-
|
|
75
|
-
container.finalize!(&block)
|
|
76
|
-
|
|
77
|
-
slices.each(&:boot)
|
|
78
|
-
|
|
79
|
-
@booted = true
|
|
80
|
-
self
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def shutdown
|
|
84
|
-
slices.each(&:shutdown)
|
|
85
|
-
container.shutdown!
|
|
86
|
-
self
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
def prepared?
|
|
90
|
-
!!@prepared
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def booted?
|
|
94
|
-
!!@booted
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
def router
|
|
98
|
-
raise "Application not yet prepared" unless prepared?
|
|
99
|
-
|
|
100
|
-
@_mutex.synchronize do
|
|
101
|
-
@_router ||= load_router
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
def rack_app
|
|
106
|
-
@rack_app ||= router.to_rack_app
|
|
107
|
-
end
|
|
108
|
-
|
|
109
|
-
def slices
|
|
110
|
-
@slices ||= SliceRegistrar.new(self)
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def register_slice(...)
|
|
114
|
-
slices.register(...)
|
|
115
|
-
end
|
|
116
|
-
|
|
117
|
-
def register(...)
|
|
118
|
-
container.register(...)
|
|
119
|
-
end
|
|
120
|
-
|
|
121
|
-
def register_provider(...)
|
|
122
|
-
container.register_provider(...)
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
def start(...)
|
|
126
|
-
container.start(...)
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def key?(...)
|
|
130
|
-
container.key?(...)
|
|
131
|
-
end
|
|
132
|
-
|
|
133
|
-
def keys
|
|
134
|
-
container.keys
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
def [](...)
|
|
138
|
-
container.[](...)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
def resolve(...)
|
|
142
|
-
container.resolve(...)
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
def settings
|
|
146
|
-
@_settings ||= load_settings
|
|
147
|
-
end
|
|
148
|
-
|
|
149
|
-
def namespace
|
|
150
|
-
configuration.namespace
|
|
151
|
-
end
|
|
152
|
-
|
|
153
|
-
def namespace_name
|
|
154
|
-
namespace.name
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
def namespace_path
|
|
158
|
-
inflector.underscore(namespace)
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
def application_name
|
|
162
|
-
configuration.application_name
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
def root
|
|
166
|
-
configuration.root
|
|
167
|
-
end
|
|
168
|
-
|
|
169
|
-
def inflector
|
|
170
|
-
configuration.inflector
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
# @api private
|
|
174
|
-
def component_provider(component)
|
|
175
|
-
raise "Hanami.application must be prepared before detecting providers" unless prepared?
|
|
176
|
-
|
|
177
|
-
# e.g. [Admin, Main, MyApp]
|
|
178
|
-
providers = slices.to_a + [self]
|
|
179
|
-
|
|
180
|
-
component_class = component.is_a?(Class) ? component : component.class
|
|
181
|
-
component_name = component_class.name
|
|
182
|
-
|
|
183
|
-
return unless component_name
|
|
184
|
-
|
|
185
|
-
providers.detect { |provider| component_name.include?(provider.namespace.to_s) }
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
private
|
|
189
|
-
|
|
190
|
-
def prepare_base_load_path
|
|
191
|
-
base_path = File.join(root, "lib")
|
|
192
|
-
$LOAD_PATH.unshift base_path unless $LOAD_PATH.include?(base_path)
|
|
193
|
-
end
|
|
194
|
-
|
|
195
|
-
def prepare_all
|
|
196
|
-
load_settings
|
|
197
|
-
prepare_container_plugins
|
|
198
|
-
prepare_container_base_config
|
|
199
|
-
prepare_container_consts
|
|
200
|
-
container.configured!
|
|
201
|
-
prepare_slices
|
|
202
|
-
# For the application, the autoloader must be prepared after the slices, since
|
|
203
|
-
# they'll be configuring the autoloader with their own dirs
|
|
204
|
-
prepare_autoloader
|
|
205
|
-
end
|
|
206
|
-
|
|
207
|
-
def prepare_container_plugins
|
|
208
|
-
container.use(:env, inferrer: -> { Hanami.env })
|
|
209
|
-
container.use(:zeitwerk, loader: autoloader, run_setup: false, eager_load: false)
|
|
210
|
-
container.use(:notifications)
|
|
211
|
-
end
|
|
212
|
-
|
|
213
|
-
def prepare_container_base_config
|
|
214
|
-
container.config.root = configuration.root
|
|
215
|
-
container.config.inflector = configuration.inflector
|
|
216
|
-
|
|
217
|
-
container.config.provider_dirs = [
|
|
218
|
-
"config/providers",
|
|
219
|
-
Pathname(__dir__).join("application/container/providers").realpath,
|
|
220
|
-
]
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
def prepare_autoload_paths
|
|
224
|
-
# Autoload classes defined in lib/[app_namespace]/
|
|
225
|
-
if root.join("lib", namespace_path).directory?
|
|
226
|
-
autoloader.push_dir(root.join("lib", namespace_path), namespace: namespace)
|
|
227
|
-
end
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
def prepare_container_consts
|
|
231
|
-
namespace.const_set :Container, container
|
|
232
|
-
namespace.const_set :Deps, container.injector
|
|
233
|
-
end
|
|
234
|
-
|
|
235
|
-
def prepare_slices
|
|
236
|
-
slices.load_slices.each(&:prepare)
|
|
237
|
-
slices.freeze
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
def prepare_autoloader
|
|
241
|
-
# Autoload classes defined in lib/[app_namespace]/
|
|
242
|
-
if root.join("lib", namespace_path).directory?
|
|
243
|
-
autoloader.push_dir(root.join("lib", namespace_path), namespace: namespace)
|
|
244
|
-
end
|
|
245
|
-
|
|
246
|
-
autoloader.setup
|
|
247
|
-
end
|
|
248
|
-
|
|
249
|
-
def load_settings
|
|
250
|
-
require_relative "application/settings"
|
|
251
|
-
|
|
252
|
-
prepare_base_load_path
|
|
253
|
-
require File.join(configuration.root, configuration.settings_path)
|
|
254
|
-
settings_class = autodiscover_application_constant(configuration.settings_class_name)
|
|
255
|
-
settings_class.new(configuration.settings_store)
|
|
256
|
-
rescue LoadError
|
|
257
|
-
Settings.new
|
|
258
|
-
end
|
|
259
|
-
|
|
260
|
-
def autodiscover_application_constant(constants)
|
|
261
|
-
inflector.constantize([namespace_name, *constants].join(MODULE_DELIMITER))
|
|
262
|
-
end
|
|
263
|
-
|
|
264
|
-
def load_router
|
|
265
|
-
require_relative "application/router"
|
|
266
|
-
|
|
267
|
-
Router.new(
|
|
268
|
-
routes: load_routes,
|
|
269
|
-
resolver: router_resolver,
|
|
270
|
-
**configuration.router.options,
|
|
271
|
-
) do
|
|
272
|
-
use Hanami.application[:rack_monitor]
|
|
273
|
-
|
|
274
|
-
Hanami.application.config.for_each_middleware do |m, *args, &block|
|
|
275
|
-
use(m, *args, &block)
|
|
276
|
-
end
|
|
277
|
-
end
|
|
278
|
-
end
|
|
279
|
-
|
|
280
|
-
def load_routes
|
|
281
|
-
require_relative "application/routes"
|
|
282
|
-
|
|
283
|
-
require File.join(configuration.root, configuration.router.routes_path)
|
|
284
|
-
routes_class = autodiscover_application_constant(configuration.router.routes_class_name)
|
|
285
|
-
routes_class.routes
|
|
286
|
-
rescue LoadError
|
|
287
|
-
proc {}
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
def router_resolver
|
|
291
|
-
config.router.resolver.new(
|
|
292
|
-
slices: slices,
|
|
293
|
-
inflector: inflector
|
|
294
|
-
)
|
|
295
|
-
end
|
|
296
|
-
end
|
|
297
|
-
# rubocop:enable Metrics/ModuleLength
|
|
298
|
-
end
|
|
299
|
-
end
|
|
@@ -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
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "hanami/cli"
|
|
4
|
-
require_relative "commands"
|
|
5
|
-
|
|
6
|
-
module Hanami
|
|
7
|
-
class CLI
|
|
8
|
-
module Application
|
|
9
|
-
# Hanami application CLI
|
|
10
|
-
class CLI < Hanami::CLI
|
|
11
|
-
attr_reader :application
|
|
12
|
-
|
|
13
|
-
def initialize(application: nil, commands: Commands)
|
|
14
|
-
super(commands)
|
|
15
|
-
@application = application
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
private
|
|
19
|
-
|
|
20
|
-
# TODO: we should make a prepare_command method upstream
|
|
21
|
-
def parse(result, out)
|
|
22
|
-
command, arguments = super
|
|
23
|
-
|
|
24
|
-
if command.respond_to?(:with_application)
|
|
25
|
-
# Set HANAMI_ENV before the application inits to ensure all aspects
|
|
26
|
-
# of the boot process respect the provided env
|
|
27
|
-
ENV["HANAMI_ENV"] = arguments[:env] if arguments[:env]
|
|
28
|
-
|
|
29
|
-
require "hanami/prepare"
|
|
30
|
-
application = Hanami.application
|
|
31
|
-
|
|
32
|
-
[command.with_application(application), arguments]
|
|
33
|
-
else
|
|
34
|
-
[command, arguments]
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require_relative "../base_command"
|
|
4
|
-
|
|
5
|
-
module Hanami
|
|
6
|
-
class CLI
|
|
7
|
-
module Application
|
|
8
|
-
# Hanami application CLI command (intended to run inside application directory)
|
|
9
|
-
class Command < BaseCommand
|
|
10
|
-
def self.inherited(klass)
|
|
11
|
-
super
|
|
12
|
-
|
|
13
|
-
klass.option :env, aliases: ["-e"], default: nil, desc: "Application environment"
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
attr_reader :application
|
|
17
|
-
|
|
18
|
-
def initialize(application: nil, **opts)
|
|
19
|
-
super(**opts)
|
|
20
|
-
@application = application
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def with_application(application)
|
|
24
|
-
self.class.new(
|
|
25
|
-
command_name: @command_name,
|
|
26
|
-
application: application,
|
|
27
|
-
out: out,
|
|
28
|
-
inflector: application.inflector,
|
|
29
|
-
files: files,
|
|
30
|
-
)
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
private
|
|
34
|
-
|
|
35
|
-
def run_command(klass, *args)
|
|
36
|
-
klass.new(
|
|
37
|
-
command_name: klass.name,
|
|
38
|
-
application: application,
|
|
39
|
-
out: out,
|
|
40
|
-
inflector: application.inflector,
|
|
41
|
-
files: files,
|
|
42
|
-
).call(*args)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "hanami/cli"
|
|
4
|
-
require "hanami/cli/application/command"
|
|
5
|
-
require "hanami/console/context"
|
|
6
|
-
|
|
7
|
-
module Hanami
|
|
8
|
-
class CLI
|
|
9
|
-
module Application
|
|
10
|
-
module Commands # rubocop:disable Style/Documentation
|
|
11
|
-
# Hanami application `console` CLI command
|
|
12
|
-
class Console < Command
|
|
13
|
-
REPL =
|
|
14
|
-
begin
|
|
15
|
-
require "pry"
|
|
16
|
-
Pry
|
|
17
|
-
rescue LoadError
|
|
18
|
-
require "irb"
|
|
19
|
-
IRB
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
desc "Open interactive console"
|
|
23
|
-
|
|
24
|
-
def call(**)
|
|
25
|
-
measure "#{prompt_prefix} booted in" do
|
|
26
|
-
out.puts "=> starting #{prompt_prefix} console"
|
|
27
|
-
application.init
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
start_repl
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
private
|
|
34
|
-
|
|
35
|
-
def start_repl
|
|
36
|
-
context = Hanami::Console::Context.new(application)
|
|
37
|
-
|
|
38
|
-
case REPL.name.to_sym
|
|
39
|
-
when :Pry
|
|
40
|
-
start_pry(context)
|
|
41
|
-
when :IRB
|
|
42
|
-
start_irb(context)
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
def start_pry(context)
|
|
47
|
-
# https://github.com/pry/pry/pull/1877
|
|
48
|
-
if Gem.loaded_specs["pry"].version >= Gem::Version.new("0.13.0")
|
|
49
|
-
Pry.prompt = Pry::Prompt.new(:hanami, "Hanami Console prompt.", prompt_procs)
|
|
50
|
-
Pry.start(context)
|
|
51
|
-
else
|
|
52
|
-
Pry.start(context, prompt_procs)
|
|
53
|
-
end
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
def start_irb(context)
|
|
57
|
-
IRB.start(context, prompt_procs)
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
def prompt_procs
|
|
61
|
-
[proc { default_prompt }, proc { indented_prompt }]
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def default_prompt
|
|
65
|
-
"#{prompt_prefix}> "
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def indented_prompt
|
|
69
|
-
"#{prompt_prefix}* "
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
def prompt_prefix
|
|
73
|
-
"#{inflector.underscore(application.application_name)}[#{application.config.env}]"
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
register "console", Console
|
|
78
|
-
end
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
end
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "hanami/cli/registry"
|
|
4
|
-
|
|
5
|
-
module Hanami
|
|
6
|
-
class CLI
|
|
7
|
-
module Application
|
|
8
|
-
# Hanami application CLI commands registry
|
|
9
|
-
module Commands
|
|
10
|
-
extend Hanami::CLI::Registry
|
|
11
|
-
|
|
12
|
-
require_relative "commands/console"
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
end
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
require "dry/inflector"
|
|
4
|
-
require "hanami/cli/command"
|
|
5
|
-
require "hanami/utils/files"
|
|
6
|
-
|
|
7
|
-
module Hanami
|
|
8
|
-
class CLI
|
|
9
|
-
# Base class for Hanami application CLI commands
|
|
10
|
-
class BaseCommand < Hanami::CLI::Command
|
|
11
|
-
attr_reader :out
|
|
12
|
-
attr_reader :inflector
|
|
13
|
-
attr_reader :files
|
|
14
|
-
|
|
15
|
-
def initialize(
|
|
16
|
-
command_name:,
|
|
17
|
-
out: $stdout,
|
|
18
|
-
inflector: Dry::Inflector.new,
|
|
19
|
-
files: Hanami::Utils::Files
|
|
20
|
-
)
|
|
21
|
-
super(command_name: command_name)
|
|
22
|
-
|
|
23
|
-
@out = out
|
|
24
|
-
@inflector = inflector
|
|
25
|
-
@files = files
|
|
26
|
-
end
|
|
27
|
-
|
|
28
|
-
private
|
|
29
|
-
|
|
30
|
-
def run_command(klass, *args)
|
|
31
|
-
klass.new(
|
|
32
|
-
command_name: klass.name,
|
|
33
|
-
application: application,
|
|
34
|
-
out: out,
|
|
35
|
-
files: files,
|
|
36
|
-
).call(*args)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def measure(desc)
|
|
40
|
-
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
41
|
-
yield
|
|
42
|
-
stop = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
43
|
-
|
|
44
|
-
out.puts "=> #{desc} in #{(stop - start).round(1)}s"
|
|
45
|
-
end
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
end
|