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,12 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require 'hanami/utils/files'
|
9
|
-
require 'erb'
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hanami"
|
4
|
+
require "hanami/cli/command"
|
5
|
+
require "concurrent"
|
6
|
+
require "hanami/utils/files"
|
7
|
+
require "erb"
|
10
8
|
|
11
9
|
module Hanami
|
12
10
|
# Hanami CLI
|
@@ -17,7 +15,7 @@ module Hanami
|
|
17
15
|
# Abstract command
|
18
16
|
#
|
19
17
|
# @since 1.1.0
|
20
|
-
class Command <
|
18
|
+
class Command < Dry::CLI::Command
|
21
19
|
# @since 1.1.0
|
22
20
|
# @api private
|
23
21
|
def self.inherited(component)
|
@@ -72,20 +70,11 @@ module Hanami
|
|
72
70
|
# @since 1.1.0
|
73
71
|
# @api private
|
74
72
|
def call(**options)
|
75
|
-
|
76
|
-
environment = Hanami::Environment.new(options)
|
77
|
-
environment.require_project_environment
|
78
|
-
|
79
|
-
requirements.resolved('environment', environment)
|
80
|
-
requirements.resolve(self.class.requirements)
|
81
|
-
|
82
|
-
options = environment.to_options.merge(options)
|
83
|
-
end
|
84
|
-
|
73
|
+
# FIXME: merge ENV vars (like HANAMI_ENV) into **options
|
85
74
|
super(options)
|
86
|
-
rescue StandardError =>
|
87
|
-
warn
|
88
|
-
warn
|
75
|
+
rescue StandardError => exception
|
76
|
+
warn exception.message
|
77
|
+
warn exception.backtrace.join("\n\t")
|
89
78
|
exit(1)
|
90
79
|
end
|
91
80
|
end
|
@@ -95,9 +84,8 @@ module Hanami
|
|
95
84
|
def initialize(command_name:, out: $stdout, files: Utils::Files)
|
96
85
|
super(command_name: command_name)
|
97
86
|
|
98
|
-
@out
|
99
|
-
@files
|
100
|
-
@templates = Templates.new(self.class)
|
87
|
+
@out = out
|
88
|
+
@files = files
|
101
89
|
end
|
102
90
|
|
103
91
|
private
|
@@ -109,7 +97,7 @@ module Hanami
|
|
109
97
|
class Renderer
|
110
98
|
# @since 1.1.0
|
111
99
|
# @api private
|
112
|
-
TRIM_MODE = "-"
|
100
|
+
TRIM_MODE = "-"
|
113
101
|
|
114
102
|
# @since 1.1.0
|
115
103
|
# @api private
|
@@ -126,7 +114,7 @@ module Hanami
|
|
126
114
|
|
127
115
|
# @since 1.1.0
|
128
116
|
# @api private
|
129
|
-
SAY_FORMATTER = "%<operation>12s %<path>s\n"
|
117
|
+
SAY_FORMATTER = "%<operation>12s %<path>s\n"
|
130
118
|
|
131
119
|
# @since 1.1.0
|
132
120
|
# @api private
|
@@ -167,13 +155,15 @@ module Hanami
|
|
167
155
|
# @since 1.1.0
|
168
156
|
# @api private
|
169
157
|
def project
|
170
|
-
|
158
|
+
# FIXME: is this still useful?
|
159
|
+
raise "it used to be implemented as Project"
|
171
160
|
end
|
172
161
|
|
173
162
|
# @since 1.1.0
|
174
163
|
# @api private
|
175
164
|
def requirements
|
176
|
-
Hanami::
|
165
|
+
# FIXME: require components via the new Hanami::Container
|
166
|
+
raise "it used to be implemented as Hanami::Components"
|
177
167
|
end
|
178
168
|
end
|
179
169
|
end
|
@@ -1,35 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module Hanami
|
4
|
+
# Hanami CLI
|
5
|
+
#
|
6
|
+
# @since 1.1.0
|
2
7
|
class CLI
|
3
8
|
module Commands
|
4
9
|
# @since 1.1.0
|
5
10
|
# @api private
|
6
11
|
class Server < Command
|
7
|
-
requires 'code_reloading'
|
8
|
-
|
9
12
|
desc "Start Hanami server (only for development)"
|
10
13
|
|
11
|
-
option :server,
|
12
|
-
option :host,
|
13
|
-
option :port,
|
14
|
-
option :debug,
|
15
|
-
option :warn,
|
16
|
-
option :daemonize,
|
17
|
-
option :pid,
|
18
|
-
option :code_reloading, desc: "Code reloading", type: :boolean, default: true
|
14
|
+
option :server, desc: "Force a server engine (eg, webrick, puma, thin, etc..)"
|
15
|
+
option :host, desc: "The host address to bind to"
|
16
|
+
option :port, desc: "The port to run the server on", aliases: ["-p"]
|
17
|
+
option :debug, desc: "Turn on debug output", type: :boolean
|
18
|
+
option :warn, desc: "Turn on warnings", type: :boolean
|
19
|
+
option :daemonize, desc: "Daemonize the server", type: :boolean
|
20
|
+
option :pid, desc: "Path to write a pid file after daemonize"
|
19
21
|
|
20
22
|
example [
|
21
23
|
" # Basic usage (it uses the bundled server engine)",
|
22
24
|
"--server=webrick # Force `webrick` server engine",
|
23
25
|
"--host=0.0.0.0 # Bind to a host",
|
24
|
-
"--port=2306 # Bind to a port"
|
25
|
-
"--no-code-reloading # Disable code reloading"
|
26
|
+
"--port=2306 # Bind to a port"
|
26
27
|
]
|
27
28
|
|
28
29
|
# @since 1.1.0
|
29
30
|
# @api private
|
30
|
-
def call(
|
31
|
+
def call(**args)
|
32
|
+
require "hanami"
|
33
|
+
require "hanami/container"
|
31
34
|
require "hanami/server"
|
32
|
-
|
35
|
+
|
36
|
+
options = parse_arguments(args)
|
37
|
+
Hanami::Server.new(options).start
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
DEFAULT_CONFIG = "config.ru"
|
43
|
+
private_constant :DEFAULT_CONFIG
|
44
|
+
|
45
|
+
DEFAULT_HOST = "0.0.0.0"
|
46
|
+
private_constant :DEFAULT_HOST
|
47
|
+
|
48
|
+
DEFAULT_PORT = "2300"
|
49
|
+
private_constant :DEFAULT_PORT
|
50
|
+
|
51
|
+
OPTIONAL_SETTINGS = %i[
|
52
|
+
server
|
53
|
+
debug
|
54
|
+
warn
|
55
|
+
daemonize
|
56
|
+
pid
|
57
|
+
].freeze
|
58
|
+
|
59
|
+
def parse_arguments(args)
|
60
|
+
Hanami::Container.start(:env)
|
61
|
+
|
62
|
+
{
|
63
|
+
config: DEFAULT_CONFIG,
|
64
|
+
Host: host(args),
|
65
|
+
Port: port(args),
|
66
|
+
AccessLog: []
|
67
|
+
}.merge(
|
68
|
+
args.slice(*OPTIONAL_SETTINGS)
|
69
|
+
)
|
70
|
+
end
|
71
|
+
|
72
|
+
def host(args)
|
73
|
+
args.fetch(:host) do
|
74
|
+
ENV.fetch("HANAMI_HOST", DEFAULT_HOST)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
def port(args)
|
79
|
+
args.fetch(:port) do
|
80
|
+
ENV.fetch("HANAMI_PORT", DEFAULT_PORT)
|
81
|
+
end
|
33
82
|
end
|
34
83
|
end
|
35
84
|
end
|
data/lib/hanami/configuration.rb
CHANGED
@@ -1,212 +1,270 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "uri"
|
4
|
+
require "concurrent/hash"
|
5
|
+
require "concurrent/array"
|
6
|
+
require "dry/inflector"
|
7
|
+
require "pathname"
|
8
|
+
require "zeitwerk"
|
5
9
|
|
6
10
|
module Hanami
|
7
|
-
#
|
11
|
+
# Hanami application configuration
|
12
|
+
#
|
13
|
+
# @since 2.0.0
|
14
|
+
#
|
15
|
+
# rubocop:disable Metrics/ClassLength
|
8
16
|
class Configuration
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
#
|
51
|
-
# migrations 'db/migrations'
|
52
|
-
# schema 'db/schema.sql'
|
53
|
-
# end
|
54
|
-
#
|
55
|
-
# # ...
|
56
|
-
# end
|
57
|
-
def model(&blk)
|
58
|
-
if block_given?
|
59
|
-
settings.put_if_absent(:model, blk)
|
60
|
-
else
|
61
|
-
settings.fetch(:model)
|
17
|
+
require_relative "configuration/middleware"
|
18
|
+
require_relative "configuration/router"
|
19
|
+
require_relative "configuration/sessions"
|
20
|
+
|
21
|
+
attr_reader :actions
|
22
|
+
attr_reader :views
|
23
|
+
|
24
|
+
# rubocop:disable Metrics/AbcSize, Metrics/MethodLength
|
25
|
+
def initialize(env:)
|
26
|
+
@settings = Concurrent::Hash.new
|
27
|
+
|
28
|
+
self.autoloader = Zeitwerk::Loader.new
|
29
|
+
|
30
|
+
self.env = env
|
31
|
+
self.environments = DEFAULT_ENVIRONMENTS.clone
|
32
|
+
|
33
|
+
self.root = Dir.pwd
|
34
|
+
self.slices_dir = DEFAULT_SLICES_DIR
|
35
|
+
settings[:slices] = {}
|
36
|
+
|
37
|
+
self.settings_path = DEFAULT_SETTINGS_PATH
|
38
|
+
self.settings_loader_options = {}
|
39
|
+
|
40
|
+
self.base_url = DEFAULT_BASE_URL
|
41
|
+
|
42
|
+
self.logger = DEFAULT_LOGGER.clone
|
43
|
+
self.rack_logger_filter_params = DEFAULT_RACK_LOGGER_FILTER_PARAMS.clone
|
44
|
+
self.sessions = DEFAULT_SESSIONS
|
45
|
+
|
46
|
+
self.router = Router.new(base_url)
|
47
|
+
self.middleware = Middleware.new
|
48
|
+
|
49
|
+
self.inflections = Dry::Inflector.new
|
50
|
+
|
51
|
+
@actions = begin
|
52
|
+
require_path = "hanami/action/application_configuration"
|
53
|
+
require require_path
|
54
|
+
Hanami::Action::ApplicationConfiguration.new
|
55
|
+
rescue LoadError => e
|
56
|
+
raise e unless e.path == require_path
|
57
|
+
Object.new
|
62
58
|
end
|
63
|
-
end
|
64
59
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
# # config/environment.rb
|
73
|
-
# # ...
|
74
|
-
# Hanami.configure do
|
75
|
-
# mailer do
|
76
|
-
# root 'lib/bookshelf/mailers'
|
77
|
-
#
|
78
|
-
# # See http://hanamirb.org/guides/mailers/delivery
|
79
|
-
# delivery :test
|
80
|
-
# end
|
81
|
-
#
|
82
|
-
# # ...
|
83
|
-
# end
|
84
|
-
def mailer(&blk)
|
85
|
-
mailer_settings.push(blk) if block_given?
|
86
|
-
end
|
87
|
-
|
88
|
-
# @since next
|
89
|
-
# @api private
|
90
|
-
def mailer_settings
|
91
|
-
settings.fetch_or_store(:mailers, [])
|
92
|
-
end
|
93
|
-
|
94
|
-
# @since 0.9.0
|
95
|
-
# @api private
|
96
|
-
def mounted
|
97
|
-
settings.fetch_or_store(:mounted, {})
|
98
|
-
end
|
99
|
-
|
100
|
-
# @since 1.2.0
|
101
|
-
#
|
102
|
-
# @example
|
103
|
-
# # config/environment.rb
|
104
|
-
# # ...
|
105
|
-
# Hanami.configure do
|
106
|
-
# middleware.use MyRackMiddleware
|
107
|
-
# end
|
108
|
-
def middleware
|
109
|
-
settings.fetch_or_store(:middleware, Configuration::Middleware.new)
|
110
|
-
end
|
111
|
-
|
112
|
-
# Setup Early Hints feature
|
113
|
-
#
|
114
|
-
# @since 1.2.0
|
115
|
-
#
|
116
|
-
# @example Enable for all the environments
|
117
|
-
# # config/environment.rb
|
118
|
-
# Hanami.configure do
|
119
|
-
# early_hints true
|
120
|
-
# end
|
121
|
-
#
|
122
|
-
# @example Enable only for production
|
123
|
-
# # config/environment.rb
|
124
|
-
# Hanami.configure do
|
125
|
-
# environment :production do
|
126
|
-
# early_hints true
|
127
|
-
# end
|
128
|
-
# end
|
129
|
-
def early_hints(value = nil)
|
130
|
-
if value.nil?
|
131
|
-
settings.fetch(:early_hints, false)
|
132
|
-
else
|
133
|
-
settings[:early_hints] = value
|
60
|
+
@views = begin
|
61
|
+
require_path = "hanami/view/application_configuration"
|
62
|
+
require require_path
|
63
|
+
Hanami::View::ApplicationConfiguration.new
|
64
|
+
rescue LoadError => e
|
65
|
+
raise e unless e.path == require_path
|
66
|
+
Object.new
|
134
67
|
end
|
135
68
|
end
|
69
|
+
# rubocop:enable Metrics/AbcSize, Metrics/MethodLength
|
136
70
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
mounted.each_pair do |klass, app|
|
141
|
-
yield(app) if klass <= Hanami::Application
|
71
|
+
def finalize
|
72
|
+
environment_for(env).each do |blk|
|
73
|
+
instance_eval(&blk)
|
142
74
|
end
|
75
|
+
|
76
|
+
# Finalize nested configuration
|
77
|
+
#
|
78
|
+
# TODO: would be good to just create empty configurations for actions/views
|
79
|
+
# instead of plain objects
|
80
|
+
actions.finalize! if actions.respond_to?(:finalize!)
|
81
|
+
views.finalize! if views.respond_to?(:finalize!)
|
82
|
+
|
83
|
+
self
|
84
|
+
end
|
85
|
+
|
86
|
+
def environment(name, &blk)
|
87
|
+
environment_for(name).push(blk)
|
88
|
+
end
|
89
|
+
|
90
|
+
def autoloader=(loader)
|
91
|
+
settings[:autoloader] = loader || nil
|
143
92
|
end
|
144
93
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
94
|
+
def autoloader
|
95
|
+
settings.fetch(:autoloader)
|
96
|
+
end
|
97
|
+
|
98
|
+
def env=(value)
|
99
|
+
settings[:env] = value
|
100
|
+
end
|
101
|
+
|
102
|
+
def env
|
103
|
+
settings.fetch(:env)
|
104
|
+
end
|
105
|
+
|
106
|
+
def root=(root)
|
107
|
+
settings[:root] = Pathname(root)
|
108
|
+
end
|
109
|
+
|
110
|
+
def root
|
111
|
+
settings.fetch(:root)
|
112
|
+
end
|
113
|
+
|
114
|
+
def slices_dir=(dir)
|
115
|
+
settings[:slices_dir] = dir
|
116
|
+
end
|
117
|
+
|
118
|
+
def slices_dir
|
119
|
+
settings.fetch(:slices_dir)
|
120
|
+
end
|
121
|
+
|
122
|
+
def slices_namespace=(namespace)
|
123
|
+
settings[:slices_namespace] = namespace
|
124
|
+
end
|
125
|
+
|
126
|
+
def slices_namespace
|
127
|
+
settings.fetch(:slices_namespace) { Object }
|
128
|
+
end
|
129
|
+
|
130
|
+
def slice(slice_name, &block)
|
131
|
+
settings[:slices][slice_name] = block
|
132
|
+
end
|
133
|
+
|
134
|
+
def slices
|
135
|
+
settings[:slices]
|
136
|
+
end
|
137
|
+
|
138
|
+
def settings_path=(value)
|
139
|
+
settings[:settings_path] = value
|
140
|
+
end
|
141
|
+
|
142
|
+
def settings_path
|
143
|
+
settings.fetch(:settings_path)
|
144
|
+
end
|
145
|
+
|
146
|
+
def settings_loader=(loader)
|
147
|
+
settings[:settings_loader] = loader
|
148
|
+
end
|
149
|
+
|
150
|
+
def settings_loader
|
151
|
+
settings.fetch(:settings_loader) {
|
152
|
+
require "hanami/application/settings/loader"
|
153
|
+
settings[:settings_loader] = Application::Settings::Loader
|
154
|
+
}
|
155
|
+
end
|
156
|
+
|
157
|
+
def settings_loader_options=(options)
|
158
|
+
settings[:settings_loader_options] = options
|
159
|
+
end
|
160
|
+
|
161
|
+
def settings_loader_options
|
162
|
+
settings[:settings_loader_options]
|
163
|
+
end
|
164
|
+
|
165
|
+
def base_url=(value)
|
166
|
+
settings[:base_url] = URI.parse(value)
|
167
|
+
end
|
168
|
+
|
169
|
+
def base_url
|
170
|
+
settings.fetch(:base_url)
|
171
|
+
end
|
172
|
+
|
173
|
+
def logger=(options)
|
174
|
+
settings[:logger] = options
|
175
|
+
end
|
176
|
+
|
177
|
+
def logger
|
178
|
+
settings.fetch(:logger)
|
179
|
+
end
|
180
|
+
|
181
|
+
def rack_logger_filter_params=(params)
|
182
|
+
settings[:rack_logger_filter_params] = params
|
183
|
+
end
|
184
|
+
|
185
|
+
def rack_logger_filter_params
|
186
|
+
settings[:rack_logger_filter_params]
|
187
|
+
end
|
188
|
+
|
189
|
+
def router=(value)
|
190
|
+
settings[:router] = value
|
191
|
+
end
|
192
|
+
|
193
|
+
def router
|
194
|
+
settings.fetch(:router)
|
195
|
+
end
|
196
|
+
|
197
|
+
def sessions=(*args)
|
198
|
+
settings[:sessions] = Sessions.new(args)
|
199
|
+
end
|
200
|
+
|
201
|
+
def sessions
|
202
|
+
settings.fetch(:sessions)
|
203
|
+
end
|
204
|
+
|
205
|
+
def middleware
|
206
|
+
settings.fetch(:middleware)
|
207
|
+
end
|
208
|
+
|
209
|
+
def inflections(&blk)
|
210
|
+
if blk.nil?
|
211
|
+
settings.fetch(:inflections)
|
178
212
|
else
|
179
|
-
settings[:
|
213
|
+
settings[:inflections] = Dry::Inflector.new(&blk)
|
180
214
|
end
|
181
215
|
end
|
182
216
|
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
217
|
+
alias inflector inflections
|
218
|
+
|
219
|
+
def for_each_middleware(&blk)
|
220
|
+
stack = middleware.stack.dup
|
221
|
+
stack += sessions.middleware if sessions.enabled?
|
222
|
+
|
223
|
+
stack.each(&blk)
|
224
|
+
end
|
225
|
+
|
226
|
+
protected
|
227
|
+
|
228
|
+
def environment_for(name)
|
229
|
+
settings[:environments][name]
|
230
|
+
end
|
231
|
+
|
232
|
+
def environments=(values)
|
233
|
+
settings[:environments] = values
|
234
|
+
end
|
235
|
+
|
236
|
+
def middleware=(value)
|
237
|
+
settings[:middleware] = value
|
238
|
+
end
|
239
|
+
|
240
|
+
def inflections=(value)
|
241
|
+
settings[:inflections] = value
|
205
242
|
end
|
206
243
|
|
207
244
|
private
|
208
245
|
|
209
|
-
|
246
|
+
DEFAULT_ENVIRONMENTS = Concurrent::Hash.new { |h, k| h[k] = Concurrent::Array.new }
|
247
|
+
private_constant :DEFAULT_ENVIRONMENTS
|
248
|
+
|
249
|
+
DEFAULT_SLICES_DIR = "slices"
|
250
|
+
private_constant :DEFAULT_SLICES_DIR
|
251
|
+
|
252
|
+
DEFAULT_BASE_URL = "http://0.0.0.0:2300"
|
253
|
+
private_constant :DEFAULT_BASE_URL
|
254
|
+
|
255
|
+
DEFAULT_LOGGER = { level: :debug }.freeze
|
256
|
+
private_constant :DEFAULT_LOGGER
|
257
|
+
|
258
|
+
DEFAULT_RACK_LOGGER_FILTER_PARAMS = %w[_csrf password password_confirmation].freeze
|
259
|
+
private_constant :DEFAULT_RACK_LOGGER_FILTER_PARAMS
|
260
|
+
|
261
|
+
DEFAULT_SETTINGS_PATH = File.join("config", "settings")
|
262
|
+
private_constant :DEFAULT_SETTINGS_PATH
|
263
|
+
|
264
|
+
DEFAULT_SESSIONS = Sessions.null
|
265
|
+
private_constant :DEFAULT_SESSIONS
|
266
|
+
|
210
267
|
attr_reader :settings
|
211
268
|
end
|
269
|
+
# rubocop:enable Metrics/ClassLength
|
212
270
|
end
|