hanami 1.3.1 → 2.0.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +110 -6
- data/FEATURES.md +9 -1
- data/LICENSE.md +1 -1
- data/README.md +4 -5
- data/hanami.gemspec +26 -30
- data/lib/hanami.rb +40 -243
- data/lib/hanami/application.rb +338 -174
- data/lib/hanami/application/autoloader/inflector_adapter.rb +22 -0
- data/lib/hanami/application/container/boot/inflector.rb +7 -0
- data/lib/hanami/application/container/boot/logger.rb +8 -0
- data/lib/hanami/application/container/boot/rack_logger.rb +19 -0
- data/lib/hanami/application/container/boot/rack_monitor.rb +12 -0
- data/lib/hanami/application/container/boot/settings.rb +7 -0
- data/lib/hanami/application/router.rb +59 -0
- data/lib/hanami/application/routing/middleware/stack.rb +89 -0
- data/lib/hanami/application/routing/resolver.rb +82 -0
- data/lib/hanami/application/routing/resolver/node.rb +50 -0
- data/lib/hanami/application/routing/resolver/trie.rb +59 -0
- data/lib/hanami/application/settings.rb +23 -0
- data/lib/hanami/application/settings/definition.rb +26 -0
- data/lib/hanami/application/settings/loader.rb +97 -0
- data/lib/hanami/application/settings/struct.rb +65 -0
- data/lib/hanami/boot.rb +5 -0
- data/lib/hanami/cli/application/cli.rb +40 -0
- data/lib/hanami/cli/application/command.rb +47 -0
- data/lib/hanami/cli/application/commands.rb +16 -0
- data/lib/hanami/cli/application/commands/console.rb +81 -0
- data/lib/hanami/cli/base_command.rb +48 -0
- data/lib/hanami/cli/commands.rb +6 -42
- data/lib/hanami/cli/commands/command.rb +20 -30
- data/lib/hanami/cli/commands/server.rb +63 -14
- data/lib/hanami/configuration.rb +248 -190
- data/lib/hanami/configuration/middleware.rb +8 -28
- data/lib/hanami/configuration/router.rb +50 -0
- data/lib/hanami/configuration/sessions.rb +50 -0
- data/lib/hanami/init.rb +5 -0
- data/lib/hanami/server.rb +5 -69
- data/lib/hanami/setup.rb +8 -2
- data/lib/hanami/slice.rb +138 -0
- data/lib/hanami/version.rb +3 -1
- data/lib/hanami/web/rack_logger.rb +96 -0
- metadata +84 -228
- data/bin/hanami +0 -6
- data/lib/hanami/action/csrf_protection.rb +0 -211
- data/lib/hanami/action/routing_helpers.rb +0 -40
- data/lib/hanami/app.rb +0 -96
- data/lib/hanami/application_configuration.rb +0 -1495
- data/lib/hanami/application_name.rb +0 -108
- data/lib/hanami/application_namespace.rb +0 -14
- data/lib/hanami/assets/asset.rb +0 -72
- data/lib/hanami/assets/static.rb +0 -102
- data/lib/hanami/cli/commands/assets.rb +0 -16
- data/lib/hanami/cli/commands/assets/precompile.rb +0 -42
- data/lib/hanami/cli/commands/console.rb +0 -95
- data/lib/hanami/cli/commands/db.rb +0 -32
- data/lib/hanami/cli/commands/db/apply.rb +0 -32
- data/lib/hanami/cli/commands/db/console.rb +0 -44
- data/lib/hanami/cli/commands/db/create.rb +0 -32
- data/lib/hanami/cli/commands/db/drop.rb +0 -32
- data/lib/hanami/cli/commands/db/migrate.rb +0 -39
- data/lib/hanami/cli/commands/db/prepare.rb +0 -32
- data/lib/hanami/cli/commands/db/rollback.rb +0 -59
- data/lib/hanami/cli/commands/db/version.rb +0 -32
- data/lib/hanami/cli/commands/destroy.rb +0 -26
- data/lib/hanami/cli/commands/destroy/action.rb +0 -137
- data/lib/hanami/cli/commands/destroy/app.rb +0 -159
- data/lib/hanami/cli/commands/destroy/mailer.rb +0 -74
- data/lib/hanami/cli/commands/destroy/migration.rb +0 -51
- data/lib/hanami/cli/commands/destroy/model.rb +0 -84
- data/lib/hanami/cli/commands/generate.rb +0 -28
- data/lib/hanami/cli/commands/generate/action.rb +0 -321
- data/lib/hanami/cli/commands/generate/action/action.erb +0 -7
- data/lib/hanami/cli/commands/generate/action/action_spec.minitest.erb +0 -11
- data/lib/hanami/cli/commands/generate/action/action_spec.rspec.erb +0 -9
- data/lib/hanami/cli/commands/generate/action/action_without_view.erb +0 -7
- data/lib/hanami/cli/commands/generate/action/view.erb +0 -7
- data/lib/hanami/cli/commands/generate/action/view_spec.minitest.erb +0 -12
- data/lib/hanami/cli/commands/generate/action/view_spec.rspec.erb +0 -10
- data/lib/hanami/cli/commands/generate/app.rb +0 -243
- data/lib/hanami/cli/commands/generate/app/application.erb +0 -313
- data/lib/hanami/cli/commands/generate/app/favicon.ico +0 -0
- data/lib/hanami/cli/commands/generate/app/gitkeep.erb +0 -0
- data/lib/hanami/cli/commands/generate/app/layout.erb +0 -7
- data/lib/hanami/cli/commands/generate/app/layout_spec.minitest.erb +0 -10
- data/lib/hanami/cli/commands/generate/app/layout_spec.rspec.erb +0 -10
- data/lib/hanami/cli/commands/generate/app/routes.erb +0 -5
- data/lib/hanami/cli/commands/generate/app/template.erb.erb +0 -10
- data/lib/hanami/cli/commands/generate/app/template.haml.erb +0 -7
- data/lib/hanami/cli/commands/generate/app/template.slim.erb +0 -8
- data/lib/hanami/cli/commands/generate/mailer.rb +0 -104
- data/lib/hanami/cli/commands/generate/mailer/mailer.erb +0 -9
- data/lib/hanami/cli/commands/generate/mailer/mailer_spec.minitest.erb +0 -7
- data/lib/hanami/cli/commands/generate/mailer/mailer_spec.rspec.erb +0 -5
- data/lib/hanami/cli/commands/generate/migration.rb +0 -41
- data/lib/hanami/cli/commands/generate/migration/migration.erb +0 -4
- data/lib/hanami/cli/commands/generate/model.rb +0 -125
- data/lib/hanami/cli/commands/generate/model/entity.erb +0 -2
- data/lib/hanami/cli/commands/generate/model/entity_spec.minitest.erb +0 -5
- data/lib/hanami/cli/commands/generate/model/entity_spec.rspec.erb +0 -3
- data/lib/hanami/cli/commands/generate/model/migration.erb +0 -10
- data/lib/hanami/cli/commands/generate/model/repository.erb +0 -5
- data/lib/hanami/cli/commands/generate/model/repository_spec.minitest.erb +0 -5
- data/lib/hanami/cli/commands/generate/model/repository_spec.rspec.erb +0 -3
- data/lib/hanami/cli/commands/generate/secret.rb +0 -48
- data/lib/hanami/cli/commands/new.rb +0 -578
- data/lib/hanami/cli/commands/new/.env.development.erb +0 -3
- data/lib/hanami/cli/commands/new/.env.test.erb +0 -3
- data/lib/hanami/cli/commands/new/.gitkeep.erb +0 -0
- data/lib/hanami/cli/commands/new/Gemfile.erb +0 -58
- data/lib/hanami/cli/commands/new/README.md.erb +0 -33
- data/lib/hanami/cli/commands/new/config.ru.erb +0 -3
- data/lib/hanami/cli/commands/new/config/boot.erb +0 -2
- data/lib/hanami/cli/commands/new/config/environment.erb +0 -49
- data/lib/hanami/cli/commands/new/gitignore.erb +0 -2
- data/lib/hanami/cli/commands/new/gitignore_with_sqlite.erb +0 -3
- data/lib/hanami/cli/commands/new/hanamirc.erb +0 -3
- data/lib/hanami/cli/commands/new/lib/project.erb +0 -2
- data/lib/hanami/cli/commands/new/minitest/Rakefile.erb +0 -12
- data/lib/hanami/cli/commands/new/minitest/features_helper.erb +0 -11
- data/lib/hanami/cli/commands/new/minitest/spec_helper.erb +0 -7
- data/lib/hanami/cli/commands/new/rspec/Rakefile.erb +0 -9
- data/lib/hanami/cli/commands/new/rspec/capybara.erb +0 -8
- data/lib/hanami/cli/commands/new/rspec/features_helper.erb +0 -12
- data/lib/hanami/cli/commands/new/rspec/rspec.erb +0 -2
- data/lib/hanami/cli/commands/new/rspec/spec_helper.erb +0 -103
- data/lib/hanami/cli/commands/new/schema.sql.erb +0 -0
- data/lib/hanami/cli/commands/project.rb +0 -421
- data/lib/hanami/cli/commands/routes.rb +0 -21
- data/lib/hanami/cli/commands/templates.rb +0 -31
- data/lib/hanami/cli/commands/version.rb +0 -19
- data/lib/hanami/common_logger.rb +0 -93
- data/lib/hanami/components.rb +0 -156
- data/lib/hanami/components/app/assets.rb +0 -59
- data/lib/hanami/components/app/controller.rb +0 -74
- data/lib/hanami/components/app/routes.rb +0 -59
- data/lib/hanami/components/app/view.rb +0 -44
- data/lib/hanami/components/component.rb +0 -182
- data/lib/hanami/components/components.rb +0 -479
- data/lib/hanami/components/routes_inspector.rb +0 -72
- data/lib/hanami/config/cookies.rb +0 -69
- data/lib/hanami/config/framework_configuration.rb +0 -43
- data/lib/hanami/config/load_paths.rb +0 -46
- data/lib/hanami/config/mapper.rb +0 -47
- data/lib/hanami/config/routes.rb +0 -20
- data/lib/hanami/config/security.rb +0 -110
- data/lib/hanami/config/sessions.rb +0 -103
- data/lib/hanami/configuration/app.rb +0 -18
- data/lib/hanami/early_hints.rb +0 -129
- data/lib/hanami/env.rb +0 -69
- data/lib/hanami/environment.rb +0 -513
- data/lib/hanami/environment_application_configurations.rb +0 -37
- data/lib/hanami/frameworks.rb +0 -22
- data/lib/hanami/hanamirc.rb +0 -169
- data/lib/hanami/mailer/glue.rb +0 -27
- data/lib/hanami/middleware_stack.rb +0 -172
- data/lib/hanami/rake_helper.rb +0 -78
- data/lib/hanami/rake_tasks.rb +0 -2
- data/lib/hanami/rendering_policy.rb +0 -95
- data/lib/hanami/routes.rb +0 -219
- data/lib/hanami/routing/default.rb +0 -32
- data/lib/hanami/static.rb +0 -63
- data/lib/hanami/templates/default.html.erb +0 -30
- data/lib/hanami/templates/welcome.html.erb +0 -52
- data/lib/hanami/views/default.rb +0 -37
- data/lib/hanami/views/default_template_finder.rb +0 -22
- data/lib/hanami/views/null_view.rb +0 -15
- data/lib/hanami/welcome.rb +0 -36
data/lib/hanami/application.rb
CHANGED
@@ -1,202 +1,366 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/system/container"
|
4
|
+
require "hanami/configuration"
|
5
|
+
require "pathname"
|
6
|
+
require "rack"
|
7
|
+
require_relative "slice"
|
8
|
+
require_relative "application/autoloader/inflector_adapter"
|
9
|
+
require_relative "application/settings"
|
8
10
|
|
9
11
|
module Hanami
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# @since 0.1.0
|
13
|
-
#
|
14
|
-
# @example
|
15
|
-
# require 'hanami'
|
12
|
+
# Hanami application class
|
16
13
|
#
|
17
|
-
#
|
18
|
-
# class Application < Hanami::Application
|
19
|
-
# end
|
20
|
-
# end
|
14
|
+
# @since 2.0.0
|
21
15
|
class Application
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
# @since 0.9.0
|
39
|
-
# @api public
|
40
|
-
#
|
41
|
-
# @example
|
42
|
-
#
|
43
|
-
# Web.routes
|
44
|
-
# Admin.routes
|
45
|
-
attr_accessor :routes
|
16
|
+
@_mutex = Mutex.new
|
17
|
+
|
18
|
+
class << self
|
19
|
+
def inherited(klass)
|
20
|
+
@_mutex.synchronize do
|
21
|
+
klass.class_eval do
|
22
|
+
@_mutex = Mutex.new
|
23
|
+
@_configuration = Hanami::Configuration.new(env: Hanami.env)
|
24
|
+
|
25
|
+
extend ClassMethods
|
26
|
+
include InstanceMethods
|
27
|
+
end
|
28
|
+
|
29
|
+
klass.send :prepare_base_load_path
|
30
|
+
|
31
|
+
Hanami.application = klass
|
46
32
|
end
|
47
33
|
end
|
48
34
|
end
|
49
35
|
|
50
|
-
#
|
36
|
+
# Application class interface
|
51
37
|
#
|
52
|
-
#
|
53
|
-
# @api private
|
38
|
+
# rubocop:disable Metrics/ModuleLength
|
54
39
|
module ClassMethods
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
def
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
40
|
+
def self.extended(klass)
|
41
|
+
klass.class_eval do
|
42
|
+
@inited = @booted = false
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def configuration
|
47
|
+
@_configuration
|
48
|
+
end
|
49
|
+
|
50
|
+
alias config configuration
|
51
|
+
|
52
|
+
def init # rubocop:disable Metrics/MethodLength
|
53
|
+
return self if inited?
|
54
|
+
|
55
|
+
configuration.finalize
|
56
|
+
|
57
|
+
load_settings
|
58
|
+
|
59
|
+
@container = prepare_container
|
60
|
+
@deps_module = prepare_deps_module
|
61
|
+
|
62
|
+
load_slices
|
63
|
+
slices.values.each(&:init)
|
64
|
+
slices.freeze
|
65
|
+
|
66
|
+
if configuration.autoloader
|
67
|
+
configuration.autoloader.inflector = Autoloader::InflectorAdapter.new(inflector)
|
68
|
+
configuration.autoloader.setup
|
69
|
+
end
|
70
|
+
|
71
|
+
load_routes
|
72
|
+
|
73
|
+
@inited = true
|
74
|
+
self
|
75
|
+
end
|
76
|
+
|
77
|
+
def inited?
|
78
|
+
@inited
|
79
|
+
end
|
80
|
+
|
81
|
+
def container
|
82
|
+
raise "Application not init'ed" unless defined?(@container)
|
83
|
+
|
84
|
+
@container
|
85
|
+
end
|
86
|
+
|
87
|
+
def deps
|
88
|
+
raise "Application not init'ed" unless defined?(@deps_module)
|
89
|
+
|
90
|
+
@deps_module
|
91
|
+
end
|
92
|
+
|
93
|
+
def slices
|
94
|
+
@slices ||= {}
|
95
|
+
end
|
96
|
+
|
97
|
+
def register_slice(name, **slice_args)
|
98
|
+
raise "Slice +#{name}+ already registered" if slices.key?(name.to_sym)
|
99
|
+
|
100
|
+
slice = Slice.new(self, name: name, **slice_args)
|
101
|
+
slice.namespace.const_set :Slice, slice if slice.namespace # rubocop:disable Style/SafeNavigation
|
102
|
+
slices[name.to_sym] = slice
|
103
|
+
end
|
104
|
+
|
105
|
+
def register(*args, **opts, &block)
|
106
|
+
container.register(*args, **opts, &block)
|
107
|
+
end
|
108
|
+
|
109
|
+
def register_bootable(*args, **opts, &block)
|
110
|
+
container.boot(*args, **opts, &block)
|
111
|
+
end
|
112
|
+
|
113
|
+
def init_bootable(*args)
|
114
|
+
container.init(*args)
|
115
|
+
end
|
116
|
+
|
117
|
+
def start_bootable(*args)
|
118
|
+
container.start(*args)
|
119
|
+
end
|
120
|
+
|
121
|
+
def key?(*args)
|
122
|
+
container.key?(*args)
|
123
|
+
end
|
124
|
+
|
125
|
+
def keys
|
126
|
+
container.keys
|
127
|
+
end
|
128
|
+
|
129
|
+
def [](*args)
|
130
|
+
container[*args]
|
131
|
+
end
|
132
|
+
|
133
|
+
def resolve(*args)
|
134
|
+
container.resolve(*args)
|
135
|
+
end
|
136
|
+
|
137
|
+
def boot(&block)
|
138
|
+
return self if booted?
|
139
|
+
|
140
|
+
init
|
141
|
+
|
142
|
+
container.finalize!(&block)
|
143
|
+
|
144
|
+
slices.values.each(&:boot)
|
145
|
+
|
146
|
+
@booted = true
|
147
|
+
self
|
148
|
+
end
|
149
|
+
|
150
|
+
def booted?
|
151
|
+
@booted
|
152
|
+
end
|
153
|
+
|
154
|
+
def settings(&block) # rubocop:disable Metrics/MethodLength
|
155
|
+
if block
|
156
|
+
@_settings = Application::Settings.build(
|
157
|
+
configuration.settings_loader,
|
158
|
+
configuration.settings_loader_options,
|
159
|
+
&block
|
160
|
+
)
|
161
|
+
elsif instance_variable_defined?(:@_settings)
|
162
|
+
@_settings
|
163
|
+
else
|
164
|
+
# Load settings lazily so they can be used to configure the
|
165
|
+
# Hanami::Application subclass (before the application has inited)
|
166
|
+
load_settings
|
167
|
+
@_settings ||= nil
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
def routes(&block)
|
172
|
+
@_mutex.synchronize do
|
173
|
+
if block.nil?
|
174
|
+
raise "Hanami.application.routes not configured" unless defined?(@_routes)
|
175
|
+
|
176
|
+
@_routes
|
177
|
+
else
|
178
|
+
@_routes = block
|
81
179
|
end
|
82
180
|
end
|
83
181
|
end
|
84
182
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
#
|
109
|
-
# @raise [RuntimeError] if the configuration is assigned more than once
|
110
|
-
#
|
111
|
-
# @since 0.1.0
|
183
|
+
MODULE_DELIMITER = "::"
|
184
|
+
private_constant :MODULE_DELIMITER
|
185
|
+
|
186
|
+
def namespace
|
187
|
+
inflector.constantize(name.split(MODULE_DELIMITER)[0..-2].join(MODULE_DELIMITER))
|
188
|
+
end
|
189
|
+
|
190
|
+
def namespace_path
|
191
|
+
inflector.underscore(namespace)
|
192
|
+
end
|
193
|
+
|
194
|
+
def application_name
|
195
|
+
inflector.underscore(namespace).to_sym
|
196
|
+
end
|
197
|
+
|
198
|
+
def root
|
199
|
+
configuration.root
|
200
|
+
end
|
201
|
+
|
202
|
+
def inflector
|
203
|
+
configuration.inflector
|
204
|
+
end
|
205
|
+
|
112
206
|
# @api private
|
113
|
-
def
|
114
|
-
|
115
|
-
|
116
|
-
|
207
|
+
def component_provider(component)
|
208
|
+
raise "Hanami.application must be inited before detecting providers" unless inited?
|
209
|
+
|
210
|
+
# [Admin, Main, MyApp] or [MyApp::Admin, MyApp::Main, MyApp]
|
211
|
+
providers = slices.values + [self]
|
212
|
+
|
213
|
+
component_class = component.is_a?(Class) ? component : component.class
|
214
|
+
component_name = component_class.name
|
215
|
+
|
216
|
+
return unless component_name
|
217
|
+
|
218
|
+
providers.detect { |provider| component_name.include?(provider.namespace.to_s) }
|
219
|
+
end
|
220
|
+
|
221
|
+
private
|
222
|
+
|
223
|
+
def prepare_base_load_path
|
224
|
+
base_path = File.join(root, "lib")
|
225
|
+
$LOAD_PATH.unshift base_path unless $LOAD_PATH.include?(base_path)
|
226
|
+
end
|
227
|
+
|
228
|
+
def prepare_container
|
229
|
+
define_container.tap do |container|
|
230
|
+
configure_container container
|
117
231
|
end
|
118
232
|
end
|
119
233
|
|
120
|
-
|
121
|
-
|
122
|
-
#
|
123
|
-
# @param environment [Symbol,nil] the configuration environment name
|
124
|
-
# @param blk [Proc] the configuration block
|
125
|
-
#
|
126
|
-
# @since 0.1.0
|
127
|
-
#
|
128
|
-
# @see Hanami::ApplicationConfiguration
|
129
|
-
#
|
130
|
-
# @example
|
131
|
-
# require 'hanami'
|
132
|
-
#
|
133
|
-
# module Bookshelf
|
134
|
-
# Application < Hanami::Application
|
135
|
-
# configure do
|
136
|
-
# # ...
|
137
|
-
# end
|
138
|
-
# end
|
139
|
-
# end
|
140
|
-
def configure(environment = nil, &blk)
|
141
|
-
configurations.add(environment, &blk)
|
234
|
+
def prepare_deps_module
|
235
|
+
define_deps_module
|
142
236
|
end
|
143
|
-
end
|
144
237
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
def initialize
|
152
|
-
@renderer = RenderingPolicy.new(configuration)
|
153
|
-
@middleware = configuration.middleware
|
154
|
-
end
|
238
|
+
def define_container
|
239
|
+
require "#{application_name}/container"
|
240
|
+
namespace.const_get :Container
|
241
|
+
rescue LoadError, NameError
|
242
|
+
namespace.const_set :Container, Class.new(Dry::System::Container)
|
243
|
+
end
|
155
244
|
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
#
|
161
|
-
# @return [Array] a serialized Rack response
|
162
|
-
#
|
163
|
-
# @since 0.1.0
|
164
|
-
#
|
165
|
-
# @see http://rack.github.io
|
166
|
-
# @see Hanami::RenderingPolicy#render
|
167
|
-
# @see Hanami::Application#middleware
|
168
|
-
def call(env)
|
169
|
-
renderer.render(env, middleware.call(env))
|
170
|
-
end
|
245
|
+
# rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
246
|
+
def configure_container(container)
|
247
|
+
container.use :env, inferrer: -> { Hanami.env }
|
248
|
+
container.use :notifications
|
171
249
|
|
172
|
-
|
250
|
+
container.configure do |config|
|
251
|
+
config.inflector = configuration.inflector
|
173
252
|
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
253
|
+
config.root = configuration.root
|
254
|
+
config.bootable_dirs = [
|
255
|
+
"config/boot",
|
256
|
+
Pathname(__dir__).join("application/container/boot").realpath,
|
257
|
+
]
|
258
|
+
|
259
|
+
if configuration.autoloader
|
260
|
+
require "dry/system/loader/autoloading"
|
261
|
+
config.component_dirs.loader = Dry::System::Loader::Autoloading
|
262
|
+
config.component_dirs.add_to_load_path = false
|
263
|
+
end
|
264
|
+
|
265
|
+
if root.join("lib").directory?
|
266
|
+
config.component_dirs.add "lib" do |dir|
|
267
|
+
dir.default_namespace = application_name.to_s
|
268
|
+
end
|
269
|
+
|
270
|
+
configuration.autoloader&.push_dir(root.join("lib"))
|
271
|
+
end
|
272
|
+
end
|
273
|
+
|
274
|
+
container
|
275
|
+
end
|
276
|
+
# rubocop:enable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
|
277
|
+
|
278
|
+
def define_deps_module
|
279
|
+
require "#{application_name}/deps"
|
280
|
+
namespace.const_get :Deps
|
281
|
+
rescue LoadError, NameError
|
282
|
+
namespace.const_set :Deps, container.injector
|
283
|
+
end
|
284
|
+
|
285
|
+
def load_slices
|
286
|
+
Dir[File.join(slices_path, "*")]
|
287
|
+
.select(&File.method(:directory?))
|
288
|
+
.each(&method(:load_slice))
|
289
|
+
end
|
290
|
+
|
291
|
+
def slices_path
|
292
|
+
File.join(root, config.slices_dir)
|
293
|
+
end
|
294
|
+
|
295
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
296
|
+
def load_slice(slice_path)
|
297
|
+
slice_path = Pathname(slice_path)
|
298
|
+
|
299
|
+
slice_name = slice_path.relative_path_from(Pathname(slices_path)).to_s
|
300
|
+
slice_const_name = inflector.camelize(slice_name)
|
301
|
+
|
302
|
+
if config.slices_namespace.const_defined?(slice_const_name)
|
303
|
+
slice_module = config.slices_namespace.const_get(slice_const_name)
|
304
|
+
|
305
|
+
raise "Cannot use slice +#{slice_const_name}+ since it is not a module" unless slice_module.is_a?(Module)
|
306
|
+
else
|
307
|
+
slice_module = Module.new
|
308
|
+
config.slices_namespace.const_set inflector.camelize(slice_name), slice_module
|
309
|
+
end
|
310
|
+
|
311
|
+
register_slice(
|
312
|
+
slice_name,
|
313
|
+
namespace: slice_module,
|
314
|
+
root: slice_path.realpath
|
315
|
+
)
|
316
|
+
end
|
317
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
318
|
+
|
319
|
+
def load_routes
|
320
|
+
require File.join(configuration.root, configuration.router.routes)
|
321
|
+
rescue LoadError # rubocop:disable Lint/SuppressedException
|
322
|
+
end
|
323
|
+
|
324
|
+
def load_settings
|
325
|
+
prepare_base_load_path
|
326
|
+
require File.join(configuration.root, configuration.settings_path)
|
327
|
+
rescue LoadError # rubocop:disable Lint/SuppressedException
|
328
|
+
end
|
182
329
|
end
|
330
|
+
# rubocop:enable Metrics/ModuleLength
|
183
331
|
|
184
|
-
#
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
# @see Hanami::RenderingPolicy
|
190
|
-
attr_reader :renderer
|
332
|
+
# Application instance interface
|
333
|
+
module InstanceMethods
|
334
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
335
|
+
def initialize(application = self.class)
|
336
|
+
require_relative "application/router"
|
191
337
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
338
|
+
application.boot
|
339
|
+
|
340
|
+
resolver = application.config.router.resolver.new(
|
341
|
+
slices: application.slices,
|
342
|
+
inflector: application.inflector
|
343
|
+
)
|
344
|
+
|
345
|
+
router = Application::Router.new(
|
346
|
+
routes: application.routes,
|
347
|
+
resolver: resolver,
|
348
|
+
**application.configuration.router.options,
|
349
|
+
) do
|
350
|
+
use application[:rack_monitor]
|
351
|
+
|
352
|
+
application.config.for_each_middleware do |m, *args, &block|
|
353
|
+
use(m, *args, &block)
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
@app = router.to_rack_app
|
358
|
+
end
|
359
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
360
|
+
|
361
|
+
def call(env)
|
362
|
+
@app.call(env)
|
363
|
+
end
|
364
|
+
end
|
201
365
|
end
|
202
366
|
end
|