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
@@ -1,59 +0,0 @@
|
|
1
|
-
require 'hanami/routes'
|
2
|
-
require 'hanami/routing/default'
|
3
|
-
|
4
|
-
module Hanami
|
5
|
-
# @since 0.9.0
|
6
|
-
# @api private
|
7
|
-
module Components
|
8
|
-
# @since 0.9.0
|
9
|
-
# @api private
|
10
|
-
module App
|
11
|
-
# hanami-router configuration for a sigle Hanami application in the project.
|
12
|
-
#
|
13
|
-
# @since 0.9.0
|
14
|
-
# @api private
|
15
|
-
class Routes
|
16
|
-
# Configure hanami-router for a single Hanami application in the project.
|
17
|
-
#
|
18
|
-
# @param app [Hanami::Configuration::App] a Hanami application
|
19
|
-
#
|
20
|
-
# @since 0.9.0
|
21
|
-
# @api private
|
22
|
-
def self.resolve(app)
|
23
|
-
namespace = app.namespace
|
24
|
-
routes = application_routes(app)
|
25
|
-
|
26
|
-
if namespace.routes.nil? # rubocop:disable Style/IfUnlessModifier
|
27
|
-
namespace.routes = Hanami::Routes.new(routes)
|
28
|
-
end
|
29
|
-
|
30
|
-
Components.resolved("#{app.app_name}.routes", routes)
|
31
|
-
end
|
32
|
-
|
33
|
-
# @since 0.9.0
|
34
|
-
# @api private
|
35
|
-
def self.application_routes(app) # rubocop:disable Metrics/MethodLength
|
36
|
-
config = app.configuration
|
37
|
-
namespace = app.namespace
|
38
|
-
|
39
|
-
resolver = Hanami::Routing::EndpointResolver.new(pattern: config.controller_pattern, namespace: namespace)
|
40
|
-
default_app = Hanami::Routing::Default.new
|
41
|
-
|
42
|
-
options = {
|
43
|
-
resolver: resolver,
|
44
|
-
default_app: default_app,
|
45
|
-
scheme: config.scheme,
|
46
|
-
host: config.host,
|
47
|
-
port: config.port,
|
48
|
-
prefix: config.path_prefix,
|
49
|
-
force_ssl: config.force_ssl
|
50
|
-
}
|
51
|
-
|
52
|
-
options[:parsers] = config.body_parsers if config.body_parsers.any?
|
53
|
-
|
54
|
-
Hanami::Router.new(options, &config.routes)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
# @since 0.9.0
|
3
|
-
# @api private
|
4
|
-
module Components
|
5
|
-
# @since 0.9.0
|
6
|
-
# @api private
|
7
|
-
module App
|
8
|
-
# hanami-view configuration for a sigle Hanami application in the project.
|
9
|
-
#
|
10
|
-
# @since 0.9.0
|
11
|
-
# @api private
|
12
|
-
class View
|
13
|
-
# Configure hanami-view for a single Hanami application in the project.
|
14
|
-
#
|
15
|
-
# @param app [Hanami::Configuration::App] a Hanami application
|
16
|
-
#
|
17
|
-
# @since 0.9.0
|
18
|
-
# @api private
|
19
|
-
#
|
20
|
-
# rubocop:disable Metrics/AbcSize
|
21
|
-
# rubocop:disable Metrics/MethodLength
|
22
|
-
def self.resolve(app)
|
23
|
-
config = app.configuration
|
24
|
-
namespace = app.namespace
|
25
|
-
|
26
|
-
unless namespace.const_defined?('View', false)
|
27
|
-
view = Hanami::View.duplicate(namespace) do
|
28
|
-
root config.templates
|
29
|
-
layout config.layout
|
30
|
-
|
31
|
-
config.view.__apply(self)
|
32
|
-
end
|
33
|
-
|
34
|
-
namespace.const_set('View', view)
|
35
|
-
end
|
36
|
-
|
37
|
-
Components.resolved "#{app.app_name}.view", namespace.const_get('View').configuration
|
38
|
-
end
|
39
|
-
end
|
40
|
-
# rubocop:enable Metrics/MethodLength
|
41
|
-
# rubocop:enable Metrics/AbcSize
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,182 +0,0 @@
|
|
1
|
-
module Hanami
|
2
|
-
# @since 0.9.0
|
3
|
-
# @api private
|
4
|
-
module Components
|
5
|
-
# Base component
|
6
|
-
#
|
7
|
-
# @since 0.9.0
|
8
|
-
# @api private
|
9
|
-
#
|
10
|
-
# @see Hanami::Components
|
11
|
-
class Component
|
12
|
-
# Instantiate a new component
|
13
|
-
#
|
14
|
-
# @param name [String] the component name
|
15
|
-
# @param blk [Proc] the logic of the component
|
16
|
-
#
|
17
|
-
# @return [Hanami::Components::Component]
|
18
|
-
#
|
19
|
-
# @since 0.9.0
|
20
|
-
# @api private
|
21
|
-
def initialize(name, &blk)
|
22
|
-
@name = name
|
23
|
-
@requirements = []
|
24
|
-
@_prepare = ->(*) {}
|
25
|
-
@_resolve = -> {}
|
26
|
-
instance_eval(&blk)
|
27
|
-
end
|
28
|
-
|
29
|
-
# Run or resolve the component
|
30
|
-
#
|
31
|
-
# @param configuration [Hanami::Configuration] the Hanami configuration for the project
|
32
|
-
#
|
33
|
-
# @since 0.9.0
|
34
|
-
# @api private
|
35
|
-
def call(configuration)
|
36
|
-
resolve_requirements
|
37
|
-
_prepare.call(configuration)
|
38
|
-
|
39
|
-
unless _run.nil?
|
40
|
-
_run.call(configuration)
|
41
|
-
return
|
42
|
-
end
|
43
|
-
|
44
|
-
resolved(name, _resolve.call(configuration))
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
# @since 1.3.0
|
50
|
-
# @api private
|
51
|
-
#
|
52
|
-
# @see Hanami::Component#logger_interface?
|
53
|
-
LOGGER_METHODS = %i[info warn debug]
|
54
|
-
|
55
|
-
# Component name
|
56
|
-
#
|
57
|
-
# @return [String]
|
58
|
-
#
|
59
|
-
# @since 0.9.0
|
60
|
-
# @api private
|
61
|
-
attr_reader :name
|
62
|
-
|
63
|
-
# Component requirements
|
64
|
-
#
|
65
|
-
# @return [Array<String>]
|
66
|
-
#
|
67
|
-
# @since 0.9.0
|
68
|
-
# @api private
|
69
|
-
attr_reader :requirements
|
70
|
-
|
71
|
-
# Prepare logic
|
72
|
-
#
|
73
|
-
# @since 0.9.0
|
74
|
-
# @api private
|
75
|
-
attr_accessor :_prepare
|
76
|
-
|
77
|
-
# Resolve logic
|
78
|
-
#
|
79
|
-
# @since 0.9.0
|
80
|
-
# @api private
|
81
|
-
attr_accessor :_resolve
|
82
|
-
|
83
|
-
# Run logic
|
84
|
-
#
|
85
|
-
# @since 0.9.0
|
86
|
-
# @api private
|
87
|
-
attr_accessor :_run
|
88
|
-
|
89
|
-
# Declare component requirement(s)
|
90
|
-
#
|
91
|
-
# @param components [Array<String>] the name of the other components to
|
92
|
-
# depend on
|
93
|
-
def requires(*components)
|
94
|
-
self.requirements = Array(components).flatten
|
95
|
-
end
|
96
|
-
|
97
|
-
# Declare prepare logic
|
98
|
-
#
|
99
|
-
# @param blk [Proc] prepare logic
|
100
|
-
#
|
101
|
-
# @since 0.9.0
|
102
|
-
# @api private
|
103
|
-
def prepare(&blk)
|
104
|
-
self._prepare = blk
|
105
|
-
end
|
106
|
-
|
107
|
-
# Declare resolve logic
|
108
|
-
#
|
109
|
-
# @param blk [Proc] resolve logic
|
110
|
-
#
|
111
|
-
# @since 0.9.0
|
112
|
-
# @api private
|
113
|
-
def resolve(&blk)
|
114
|
-
self._resolve = blk
|
115
|
-
end
|
116
|
-
|
117
|
-
# Declare run logic
|
118
|
-
#
|
119
|
-
# @param blk [Proc] run logic
|
120
|
-
#
|
121
|
-
# @since 0.9.0
|
122
|
-
# @api private
|
123
|
-
def run(&blk)
|
124
|
-
self._run = blk
|
125
|
-
end
|
126
|
-
|
127
|
-
# Set requirements
|
128
|
-
#
|
129
|
-
# @param names [Array<String>] the requirements
|
130
|
-
#
|
131
|
-
# @since 0.9.0
|
132
|
-
# @api private
|
133
|
-
def requirements=(names)
|
134
|
-
@requirements = Array(names).flatten
|
135
|
-
end
|
136
|
-
|
137
|
-
# Resolve the requirements before to execute the logic of this component
|
138
|
-
#
|
139
|
-
# @since 0.9.0
|
140
|
-
# @api private
|
141
|
-
#
|
142
|
-
# @see Hanami::Components.resolve
|
143
|
-
def resolve_requirements
|
144
|
-
Components.resolve(requirements)
|
145
|
-
end
|
146
|
-
|
147
|
-
# Get a registered component by name
|
148
|
-
#
|
149
|
-
# @param name [String] the component name
|
150
|
-
#
|
151
|
-
# @since 0.9.0
|
152
|
-
# @api private
|
153
|
-
#
|
154
|
-
# @see Hanami::Components.component
|
155
|
-
def component(name)
|
156
|
-
Components.component(name)
|
157
|
-
end
|
158
|
-
|
159
|
-
# Mark a component as resolved by providing a value or a block.
|
160
|
-
#
|
161
|
-
# @param name [String] the name of the component to mark as resolved
|
162
|
-
# @param value [Object] the optional value of the component
|
163
|
-
# @param blk [Proc] the optional block which returning value is associated with the component.
|
164
|
-
#
|
165
|
-
# @since 0.9.0
|
166
|
-
# @api private
|
167
|
-
#
|
168
|
-
# @see Hanami::Components.resolved
|
169
|
-
def resolved(name, value = nil, &blk)
|
170
|
-
Components.resolved(name, value, &blk)
|
171
|
-
end
|
172
|
-
|
173
|
-
# Check that instance has logger interfaces (#info, #warn and #debug)
|
174
|
-
#
|
175
|
-
# @since 1.3.0
|
176
|
-
# @api private
|
177
|
-
def logger_interface?(instance)
|
178
|
-
LOGGER_METHODS.all? { |method| instance.respond_to?(method) }
|
179
|
-
end
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
@@ -1,479 +0,0 @@
|
|
1
|
-
require 'hanami/utils'
|
2
|
-
|
3
|
-
module Hanami
|
4
|
-
# Registered components
|
5
|
-
#
|
6
|
-
# @since 0.9.0
|
7
|
-
# @api private
|
8
|
-
#
|
9
|
-
# @see Hanami::Components
|
10
|
-
module Components # rubocop:disable Metrics/ModuleLength
|
11
|
-
# Require the entire project
|
12
|
-
#
|
13
|
-
# @since 0.9.0
|
14
|
-
# @api private
|
15
|
-
register 'all' do
|
16
|
-
requires 'logger', 'code', 'mailer', 'model', 'apps', 'finalizers'
|
17
|
-
|
18
|
-
resolve { true }
|
19
|
-
end
|
20
|
-
|
21
|
-
# Setup project's logger
|
22
|
-
#
|
23
|
-
# @since 1.0.0
|
24
|
-
# @api private
|
25
|
-
register 'logger' do
|
26
|
-
prepare do
|
27
|
-
require 'hanami/logger'
|
28
|
-
end
|
29
|
-
|
30
|
-
resolve do |configuration|
|
31
|
-
if configuration.logger.is_a?(Array)
|
32
|
-
if logger_interface?(configuration.logger.first)
|
33
|
-
configuration.logger.first
|
34
|
-
else
|
35
|
-
Hanami::Logger.new(Hanami.environment.project_name, *configuration.logger)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Check if code reloading is enabled
|
42
|
-
#
|
43
|
-
# @since 0.9.0
|
44
|
-
# @api private
|
45
|
-
register 'code_reloading' do
|
46
|
-
prepare do
|
47
|
-
begin
|
48
|
-
require 'shotgun'
|
49
|
-
rescue LoadError # rubocop:disable Lint/HandleExceptions
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
resolve do
|
54
|
-
!!(defined?(Shotgun) && # rubocop:disable Style/DoubleNegation
|
55
|
-
Components['environment'].code_reloading?)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
# @api private
|
60
|
-
register 'code' do
|
61
|
-
run do
|
62
|
-
directory = Hanami.root.join('lib')
|
63
|
-
|
64
|
-
if Hanami.code_reloading?
|
65
|
-
Utils.reload!(directory)
|
66
|
-
else
|
67
|
-
Utils.require!(directory)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
# Tries to load hanami-model, if available for the project
|
73
|
-
#
|
74
|
-
# @since 0.9.0
|
75
|
-
# @api private
|
76
|
-
#
|
77
|
-
# @example With hanami-model
|
78
|
-
# Hanami::Components.resolve('model')
|
79
|
-
# Hanami::Components['model'] # => true
|
80
|
-
#
|
81
|
-
# @example Without hanami-model
|
82
|
-
# Hanami::Components.resolve('model')
|
83
|
-
# Hanami::Components['model'] # => nil
|
84
|
-
register 'model' do
|
85
|
-
requires 'logger', 'model.configuration', 'model.sql'
|
86
|
-
|
87
|
-
resolve do
|
88
|
-
if Components['model.configuration']
|
89
|
-
Hanami::Model.load!
|
90
|
-
Hanami::Model.configuration.logger = Components['logger']
|
91
|
-
true
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
# Tries to evaluate hanami-model configuration, if available for the project
|
97
|
-
#
|
98
|
-
# @since 0.9.0
|
99
|
-
# @api private
|
100
|
-
#
|
101
|
-
# @example With hanami-model
|
102
|
-
# Hanami::Components.resolve('model.configuration')
|
103
|
-
# Hanami::Components['model.configuration'].class # => Hanami::Model::Configuration
|
104
|
-
#
|
105
|
-
# @example Without hanami-model
|
106
|
-
# Hanami::Components.resolve('model.configuration')
|
107
|
-
# Hanami::Components['model.configuration'].class # => NilClass
|
108
|
-
register 'model.configuration' do
|
109
|
-
requires 'model.bundled'
|
110
|
-
|
111
|
-
resolve do |configuration|
|
112
|
-
if Components['model.bundled']
|
113
|
-
Hanami::Model.instance_variable_set(:@configuration, nil) if Hanami.code_reloading?
|
114
|
-
Hanami::Model.configure(&configuration.model)
|
115
|
-
Hanami::Model.configuration
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
|
120
|
-
# Tries to evaluate hanami-model configuration, if available for the project
|
121
|
-
# and it doesn't activate migrations logger
|
122
|
-
#
|
123
|
-
# @since 1.1.0
|
124
|
-
# @api private
|
125
|
-
#
|
126
|
-
# @example With hanami-model
|
127
|
-
# Hanami::Components.resolve('model.configuration.no_logger')
|
128
|
-
# Hanami::Components['model.configuration.no_logger'].class # => Hanami::Model::Configuration
|
129
|
-
#
|
130
|
-
# @example Without hanami-model
|
131
|
-
# Hanami::Components.resolve('model.configuration.no_logger')
|
132
|
-
# Hanami::Components['model.configuration.no_logger'].class # => NilClass
|
133
|
-
register 'model.configuration.no_logger' do
|
134
|
-
requires 'model.bundled'
|
135
|
-
|
136
|
-
prepare do
|
137
|
-
require 'stringio'
|
138
|
-
end
|
139
|
-
|
140
|
-
resolve do |configuration|
|
141
|
-
if Components['model.bundled']
|
142
|
-
Hanami::Model.configure(&configuration.model)
|
143
|
-
Hanami::Model.config.migrations_logger(StringIO.new)
|
144
|
-
Hanami::Model.configuration
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
# Tries to load SQL support for hanami, if available for the project
|
150
|
-
#
|
151
|
-
# @since 0.9.0
|
152
|
-
# @api private
|
153
|
-
#
|
154
|
-
# @example With hanami-model
|
155
|
-
# Hanami::Components.resolve('model.sql')
|
156
|
-
# Hanami::Components['model.sql'] # => true
|
157
|
-
#
|
158
|
-
# @example Without hanami-model
|
159
|
-
# Hanami::Components.resolve('model.sql')
|
160
|
-
# Hanami::Components['model.sql'] # => nil
|
161
|
-
register 'model.sql' do
|
162
|
-
requires 'model.configuration'
|
163
|
-
|
164
|
-
prepare do
|
165
|
-
begin
|
166
|
-
require 'hanami/model/sql'
|
167
|
-
rescue LoadError # rubocop:disable Lint/HandleExceptions
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
resolve do
|
172
|
-
true if defined?(Hanami::Model::Sql)
|
173
|
-
end
|
174
|
-
end
|
175
|
-
|
176
|
-
# Check if hanami-model is bundled
|
177
|
-
#
|
178
|
-
# @since 0.9.0
|
179
|
-
# @api private
|
180
|
-
#
|
181
|
-
# @example With hanami-model
|
182
|
-
# Hanami::Components.resolve('model.bundled')
|
183
|
-
# Hanami::Components['model.bundled'] # => true
|
184
|
-
#
|
185
|
-
# @example Without hanami-model
|
186
|
-
# Hanami::Components.resolve('model.bundled')
|
187
|
-
# Hanami::Components['model.bundled'] # => nil
|
188
|
-
register 'model.bundled' do
|
189
|
-
prepare do
|
190
|
-
begin
|
191
|
-
require 'hanami/model'
|
192
|
-
rescue LoadError # rubocop:disable Lint/HandleExceptions
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
resolve do
|
197
|
-
true if defined?(Hanami::Model)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
# Tries to evaluate hanami-mailer configuration
|
202
|
-
#
|
203
|
-
# @since 1.0.0
|
204
|
-
# @api private
|
205
|
-
#
|
206
|
-
# @example With hanami-mailer
|
207
|
-
# Hanami::Components.resolve('mailer.configuration')
|
208
|
-
# Hanami::Components['mailer.configuration'].class # => Hanami::Mailer::Configuration
|
209
|
-
register 'mailer.configuration' do
|
210
|
-
prepare do
|
211
|
-
require 'hanami/mailer'
|
212
|
-
require 'hanami/mailer/glue'
|
213
|
-
end
|
214
|
-
|
215
|
-
resolve do |configuration|
|
216
|
-
unless configuration.mailer_settings.empty?
|
217
|
-
if Hanami.code_reloading? && !Hanami::Mailer.configuration.nil?
|
218
|
-
Hanami::Mailer.configuration = Hanami::Mailer.configuration.dup
|
219
|
-
end
|
220
|
-
|
221
|
-
configuration.mailer_settings.each do |settings|
|
222
|
-
Hanami::Mailer.configure(&settings)
|
223
|
-
Hanami::Mailer.configuration.mailers.each do |mailer|
|
224
|
-
mailer.configuration = Hanami::Mailer.configuration.duplicate
|
225
|
-
Hanami::Mailer.configuration.copy!(mailer)
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
Hanami::Mailer.configuration
|
230
|
-
end
|
231
|
-
end
|
232
|
-
end
|
233
|
-
|
234
|
-
# Tries to load hanami-mailer
|
235
|
-
#
|
236
|
-
# @since 1.0.0
|
237
|
-
# @api private
|
238
|
-
#
|
239
|
-
# @example
|
240
|
-
# Hanami::Components.resolve('mailer')
|
241
|
-
# Hanami::Components['mailer'] # => true
|
242
|
-
register 'mailer' do
|
243
|
-
requires 'mailer.configuration'
|
244
|
-
|
245
|
-
resolve do
|
246
|
-
if Components['mailer.configuration']
|
247
|
-
Hanami::Mailer.load!
|
248
|
-
true
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
|
253
|
-
# Loads the routes for all the mounted Hanami/Rack applications
|
254
|
-
#
|
255
|
-
# This is used only by `hanami routes` command.
|
256
|
-
#
|
257
|
-
# @since 0.9.0
|
258
|
-
# @api private
|
259
|
-
register 'routes.inspector' do
|
260
|
-
requires 'apps.configurations'
|
261
|
-
|
262
|
-
prepare do
|
263
|
-
require 'hanami/components/routes_inspector'
|
264
|
-
end
|
265
|
-
|
266
|
-
resolve do |configuration|
|
267
|
-
RoutesInspector.new(configuration)
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
# Loads all the Hanami applications in the project
|
272
|
-
#
|
273
|
-
# @since 0.9.0
|
274
|
-
# @api private
|
275
|
-
register 'apps' do
|
276
|
-
resolve do |configuration|
|
277
|
-
configuration.apps do |app|
|
278
|
-
component('app').call(app)
|
279
|
-
end
|
280
|
-
|
281
|
-
true
|
282
|
-
end
|
283
|
-
end
|
284
|
-
|
285
|
-
# Evaluates all the Hanami applications' configurations in the project
|
286
|
-
#
|
287
|
-
# @since 0.9.0
|
288
|
-
# @api private
|
289
|
-
register 'apps.configurations' do
|
290
|
-
resolve do |configuration|
|
291
|
-
configuration.apps do |app|
|
292
|
-
component('app.configuration').call(app)
|
293
|
-
end
|
294
|
-
|
295
|
-
true
|
296
|
-
end
|
297
|
-
end
|
298
|
-
|
299
|
-
# Evaluates all the Hanami assets configurations for each application in the project
|
300
|
-
#
|
301
|
-
# This is used only by `hanami assets precompile` command.
|
302
|
-
#
|
303
|
-
# @since 0.9.0
|
304
|
-
# @api private
|
305
|
-
register 'apps.assets.configurations' do
|
306
|
-
requires 'apps.configurations'
|
307
|
-
|
308
|
-
prepare do
|
309
|
-
require 'hanami/components/app/assets'
|
310
|
-
end
|
311
|
-
|
312
|
-
resolve do |configuration|
|
313
|
-
[].tap do |result|
|
314
|
-
configuration.apps do |app|
|
315
|
-
result << Components::App::Assets.resolve(app)
|
316
|
-
end
|
317
|
-
end
|
318
|
-
end
|
319
|
-
end
|
320
|
-
|
321
|
-
# Finalizers for the project
|
322
|
-
#
|
323
|
-
# @since 0.9.0
|
324
|
-
# @api private
|
325
|
-
register 'finalizers' do
|
326
|
-
requires 'plugins', 'finalizers.initializers'
|
327
|
-
|
328
|
-
resolve { true }
|
329
|
-
end
|
330
|
-
|
331
|
-
# Load project initializers
|
332
|
-
#
|
333
|
-
# @since 0.9.0
|
334
|
-
# @api private
|
335
|
-
register 'finalizers.initializers' do
|
336
|
-
run do
|
337
|
-
Hanami::Utils.require!(
|
338
|
-
Hanami.root.join('config', 'initializers')
|
339
|
-
)
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
# Load plugins
|
344
|
-
#
|
345
|
-
# @since 1.2.0
|
346
|
-
# @api private
|
347
|
-
register 'plugins' do
|
348
|
-
resolve do |configuration|
|
349
|
-
Hanami.plugins.each do |plugin_configuration|
|
350
|
-
configuration.instance_eval(&plugin_configuration)
|
351
|
-
end
|
352
|
-
end
|
353
|
-
end
|
354
|
-
|
355
|
-
# Configure, load and finalize a Hanami application in the project
|
356
|
-
#
|
357
|
-
# @since 0.9.0
|
358
|
-
# @api private
|
359
|
-
register 'app' do
|
360
|
-
run do |app|
|
361
|
-
['app.configuration', 'app.frameworks', 'app.code', 'app.routes', 'app.finalizer'].each do |c|
|
362
|
-
component(c).call(app)
|
363
|
-
end
|
364
|
-
|
365
|
-
resolved(app.app_name, true)
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
|
-
# Evaluate the configuration of a single Hanami application in the project
|
370
|
-
#
|
371
|
-
# @since 0.9.0
|
372
|
-
# @api private
|
373
|
-
register 'app.configuration' do
|
374
|
-
run do |app|
|
375
|
-
resolved("#{app.app_name}.configuration") do
|
376
|
-
ApplicationConfiguration.new(app.namespace, app.configurations, app.path_prefix).tap do |config|
|
377
|
-
app.configuration = config
|
378
|
-
end
|
379
|
-
end
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
# Evaluate Hanami frameworks configurations of a single Hanami application in the project
|
384
|
-
#
|
385
|
-
# @since 0.9.0
|
386
|
-
# @api private
|
387
|
-
register 'app.frameworks' do
|
388
|
-
run do |app|
|
389
|
-
['app.controller', 'app.view', 'app.assets'].each do |c|
|
390
|
-
component(c).call(app)
|
391
|
-
end
|
392
|
-
end
|
393
|
-
end
|
394
|
-
|
395
|
-
# Evaluate hanami-controller configuration of a single Hanami application in the project
|
396
|
-
#
|
397
|
-
# @since 0.9.0
|
398
|
-
# @api private
|
399
|
-
register 'app.controller' do
|
400
|
-
prepare do
|
401
|
-
require 'hanami/components/app/controller'
|
402
|
-
end
|
403
|
-
|
404
|
-
run do |app|
|
405
|
-
Components::App::Controller.resolve(app)
|
406
|
-
end
|
407
|
-
end
|
408
|
-
|
409
|
-
# Evaluate hanami-view configuration of a single Hanami application in the project
|
410
|
-
#
|
411
|
-
# @since 0.9.0
|
412
|
-
# @api private
|
413
|
-
register 'app.view' do
|
414
|
-
prepare do
|
415
|
-
require 'hanami/components/app/view'
|
416
|
-
end
|
417
|
-
|
418
|
-
run do |app|
|
419
|
-
Components::App::View.resolve(app)
|
420
|
-
end
|
421
|
-
end
|
422
|
-
|
423
|
-
# Evaluate hanami-assets configuration of a single Hanami application in the project
|
424
|
-
#
|
425
|
-
# @since 0.9.0
|
426
|
-
# @api private
|
427
|
-
register 'app.assets' do
|
428
|
-
prepare do
|
429
|
-
require 'hanami/components/app/assets'
|
430
|
-
end
|
431
|
-
|
432
|
-
run do |app|
|
433
|
-
Components::App::Assets.resolve(app)
|
434
|
-
end
|
435
|
-
end
|
436
|
-
|
437
|
-
# Load the code for a single Hanami application in the project
|
438
|
-
#
|
439
|
-
# @since 0.9.0
|
440
|
-
# @api private
|
441
|
-
register 'app.code' do
|
442
|
-
run do |app|
|
443
|
-
config = app.configuration
|
444
|
-
config.load_paths.load!
|
445
|
-
end
|
446
|
-
end
|
447
|
-
|
448
|
-
# Load the routes for a single Hanami application in the project
|
449
|
-
#
|
450
|
-
# @since 0.9.0
|
451
|
-
# @api private
|
452
|
-
register 'app.routes' do
|
453
|
-
prepare do
|
454
|
-
require 'hanami/components/app/routes'
|
455
|
-
end
|
456
|
-
|
457
|
-
run do |app|
|
458
|
-
Components::App::Routes.resolve(app)
|
459
|
-
end
|
460
|
-
end
|
461
|
-
|
462
|
-
# Finalize a single Hanami application in the project
|
463
|
-
#
|
464
|
-
# @since 0.9.0
|
465
|
-
# @api private
|
466
|
-
register 'app.finalizer' do
|
467
|
-
run do |app|
|
468
|
-
config = app.configuration
|
469
|
-
namespace = app.namespace
|
470
|
-
|
471
|
-
config.middleware.load!
|
472
|
-
|
473
|
-
namespace.module_eval %(#{namespace}::Controller.load!)
|
474
|
-
namespace.module_eval %(#{namespace}::View.load!)
|
475
|
-
namespace.module_eval %(#{namespace}::Assets.load!)
|
476
|
-
end
|
477
|
-
end
|
478
|
-
end
|
479
|
-
end
|