hanami 1.3.5 → 2.0.0.alpha1
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 +51 -41
- data/FEATURES.md +2 -12
- data/LICENSE.md +1 -1
- data/README.md +5 -8
- data/bin/hanami +6 -4
- data/hanami.gemspec +24 -28
- data/lib/hanami/application.rb +44 -176
- data/lib/hanami/boot.rb +6 -0
- data/lib/hanami/cli/commands/command.rb +21 -29
- data/lib/hanami/cli/commands/server.rb +63 -14
- data/lib/hanami/cli/commands.rb +5 -42
- data/lib/hanami/configuration/cookies.rb +24 -0
- data/lib/hanami/configuration/middleware.rb +8 -28
- data/lib/hanami/configuration/security.rb +141 -0
- data/lib/hanami/configuration/sessions.rb +50 -0
- data/lib/hanami/configuration.rb +181 -191
- data/lib/hanami/container.rb +107 -0
- data/lib/hanami/frameworks.rb +24 -18
- data/lib/hanami/routes.rb +17 -205
- data/lib/hanami/server.rb +5 -69
- data/lib/hanami/version.rb +3 -1
- data/lib/hanami.rb +39 -243
- metadata +36 -233
- 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/precompile.rb +0 -42
- data/lib/hanami/cli/commands/assets.rb +0 -16
- data/lib/hanami/cli/commands/console.rb +0 -95
- 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/db.rb +0 -32
- 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/destroy.rb +0 -26
- 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/action.rb +0 -321
- 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/app.rb +0 -243
- 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/mailer.rb +0 -104
- data/lib/hanami/cli/commands/generate/migration/migration.erb +0 -4
- data/lib/hanami/cli/commands/generate/migration.rb +0 -41
- 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/model.rb +0 -125
- data/lib/hanami/cli/commands/generate/secret.rb +0 -48
- data/lib/hanami/cli/commands/generate.rb +0 -28
- 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 -57
- data/lib/hanami/cli/commands/new/README.md.erb +0 -33
- 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/config.ru.erb +0 -3
- data/lib/hanami/cli/commands/new/gitignore.erb +0 -4
- data/lib/hanami/cli/commands/new/gitignore_with_sqlite.erb +0 -5
- 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/new.rb +0 -578
- 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 -109
- 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/components.rb +0 -156
- 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 -119
- data/lib/hanami/configuration/app.rb +0 -21
- data/lib/hanami/early_hints.rb +0 -129
- data/lib/hanami/env.rb +0 -69
- data/lib/hanami/environment.rb +0 -541
- data/lib/hanami/environment_application_configurations.rb +0 -37
- 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 -3
- data/lib/hanami/rendering_policy.rb +0 -94
- data/lib/hanami/routing/default.rb +0 -32
- data/lib/hanami/setup.rb +0 -3
- 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 -41
data/lib/hanami/environment.rb
DELETED
|
@@ -1,541 +0,0 @@
|
|
|
1
|
-
require 'thread'
|
|
2
|
-
require 'pathname'
|
|
3
|
-
require 'hanami/utils'
|
|
4
|
-
require 'hanami/utils/hash'
|
|
5
|
-
require 'hanami/env'
|
|
6
|
-
require 'hanami/hanamirc'
|
|
7
|
-
require 'hanami/components'
|
|
8
|
-
|
|
9
|
-
module Hanami
|
|
10
|
-
# Define and expose information about the Hanami environment.
|
|
11
|
-
#
|
|
12
|
-
# @since 0.1.0
|
|
13
|
-
# @api private
|
|
14
|
-
class Environment
|
|
15
|
-
# Global lock (used to serialize process of environment configuration)
|
|
16
|
-
#
|
|
17
|
-
# @since 0.8.0
|
|
18
|
-
# @api private
|
|
19
|
-
LOCK = Mutex.new
|
|
20
|
-
|
|
21
|
-
# Standard Rack ENV key
|
|
22
|
-
#
|
|
23
|
-
# @since 0.1.0
|
|
24
|
-
# @api private
|
|
25
|
-
RACK_ENV = 'RACK_ENV'.freeze
|
|
26
|
-
|
|
27
|
-
# Standard Hanami ENV key
|
|
28
|
-
#
|
|
29
|
-
# @since 0.1.0
|
|
30
|
-
# @api private
|
|
31
|
-
HANAMI_ENV = 'HANAMI_ENV'.freeze
|
|
32
|
-
|
|
33
|
-
# Default Hanami environment
|
|
34
|
-
#
|
|
35
|
-
# @since 0.1.0
|
|
36
|
-
# @api private
|
|
37
|
-
DEFAULT_ENV = 'development'.freeze
|
|
38
|
-
|
|
39
|
-
# Test environment
|
|
40
|
-
#
|
|
41
|
-
# @since 1.3.3
|
|
42
|
-
# @api private
|
|
43
|
-
TEST_ENV = 'test'.freeze
|
|
44
|
-
|
|
45
|
-
# Production environment
|
|
46
|
-
#
|
|
47
|
-
# @since 0.6.0
|
|
48
|
-
# @api private
|
|
49
|
-
PRODUCTION_ENV = 'production'.freeze
|
|
50
|
-
|
|
51
|
-
# Rack production environment (aka deployment)
|
|
52
|
-
#
|
|
53
|
-
# @since 0.6.0
|
|
54
|
-
# @api private
|
|
55
|
-
RACK_ENV_DEPLOYMENT = 'deployment'.freeze
|
|
56
|
-
|
|
57
|
-
# @since 1.3.3
|
|
58
|
-
# @api private
|
|
59
|
-
DOTENV_LOCAL_FILE = '.env.local'.freeze
|
|
60
|
-
|
|
61
|
-
# Default `.env` files that are loaded. The entries are ordered from highest
|
|
62
|
-
# to lowest priority.
|
|
63
|
-
#
|
|
64
|
-
# @since 1.3.3
|
|
65
|
-
# @api private
|
|
66
|
-
DOTENV_FILES = [
|
|
67
|
-
'.env.%{environment}.local'.freeze,
|
|
68
|
-
DOTENV_LOCAL_FILE,
|
|
69
|
-
'.env.%{environment}'.freeze,
|
|
70
|
-
'.env'.freeze
|
|
71
|
-
].freeze
|
|
72
|
-
|
|
73
|
-
# Default configuration directory under application root
|
|
74
|
-
#
|
|
75
|
-
# @since 0.2.0
|
|
76
|
-
# @api private
|
|
77
|
-
DEFAULT_CONFIG = 'config'.freeze
|
|
78
|
-
|
|
79
|
-
# Standard Hanami host ENV key
|
|
80
|
-
#
|
|
81
|
-
# @since 0.1.0
|
|
82
|
-
# @api private
|
|
83
|
-
HANAMI_HOST = 'HANAMI_HOST'.freeze
|
|
84
|
-
|
|
85
|
-
# Default HTTP host
|
|
86
|
-
#
|
|
87
|
-
# @since 0.1.0
|
|
88
|
-
# @api private
|
|
89
|
-
DEFAULT_HOST = 'localhost'.freeze
|
|
90
|
-
|
|
91
|
-
# Default IP address listen
|
|
92
|
-
#
|
|
93
|
-
# @since 0.1.0
|
|
94
|
-
# @api private
|
|
95
|
-
LISTEN_ALL_HOST = '0.0.0.0'.freeze
|
|
96
|
-
|
|
97
|
-
# Standard Hanami port ENV key
|
|
98
|
-
#
|
|
99
|
-
# @since 0.1.0
|
|
100
|
-
# @api private
|
|
101
|
-
HANAMI_PORT = 'HANAMI_PORT'.freeze
|
|
102
|
-
|
|
103
|
-
# Default Hanami HTTP port
|
|
104
|
-
#
|
|
105
|
-
# @since 0.1.0
|
|
106
|
-
# @api private
|
|
107
|
-
DEFAULT_PORT = 2300
|
|
108
|
-
|
|
109
|
-
# Default Rack configuration file
|
|
110
|
-
#
|
|
111
|
-
# @since 0.2.0
|
|
112
|
-
# @api private
|
|
113
|
-
DEFAULT_RACKUP = 'config.ru'.freeze
|
|
114
|
-
|
|
115
|
-
# Default environment configuration file
|
|
116
|
-
#
|
|
117
|
-
# @since 0.2.0
|
|
118
|
-
# @api private
|
|
119
|
-
DEFAULT_ENVIRONMENT_CONFIG = 'environment'.freeze
|
|
120
|
-
|
|
121
|
-
# Code reloading per environment
|
|
122
|
-
#
|
|
123
|
-
# @since 0.2.0
|
|
124
|
-
# @api private
|
|
125
|
-
CODE_RELOADING = { 'development' => true }.freeze
|
|
126
|
-
|
|
127
|
-
# @since 0.4.0
|
|
128
|
-
# @api private
|
|
129
|
-
APPS_PATH = 'apps'.freeze
|
|
130
|
-
|
|
131
|
-
# @since 0.4.0
|
|
132
|
-
# @api private
|
|
133
|
-
SERVE_STATIC_ASSETS = 'SERVE_STATIC_ASSETS'.freeze
|
|
134
|
-
|
|
135
|
-
# @since 0.4.0
|
|
136
|
-
# @api private
|
|
137
|
-
SERVE_STATIC_ASSETS_ENABLED = 'true'.freeze
|
|
138
|
-
|
|
139
|
-
# Initialize a Hanami environment
|
|
140
|
-
#
|
|
141
|
-
# It accepts an optional set of configurations from the CLI commands.
|
|
142
|
-
# Those settings override the defaults defined by this object.
|
|
143
|
-
#
|
|
144
|
-
# When initialized, it sets standard `ENV` variables for Rack and Hanami,
|
|
145
|
-
# such as `RACK_ENV` and `HANAMI_ENV`.
|
|
146
|
-
#
|
|
147
|
-
# It evaluates configuration ONLY from `.env.<environment>` file
|
|
148
|
-
# located under the config directory. All the settings in those files will
|
|
149
|
-
# be exported as `ENV` variables.
|
|
150
|
-
#
|
|
151
|
-
# This table: https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
|
152
|
-
# has more info on the priority of the .env files.
|
|
153
|
-
#
|
|
154
|
-
# The format of those `.env.<environment>` files follows UNIX and UNIX-like
|
|
155
|
-
# operating system environment variable declaration format and compatible
|
|
156
|
-
# with `dotenv` and `foreman` gems.
|
|
157
|
-
#
|
|
158
|
-
# @param options [Hash] override default options for various environment
|
|
159
|
-
# attributes
|
|
160
|
-
#
|
|
161
|
-
# @return [Hanami::Environment] the environment
|
|
162
|
-
#
|
|
163
|
-
# @see Hanami::Commands::Console
|
|
164
|
-
# @see Hanami::Commands::Routes
|
|
165
|
-
# @see Hanami::Commands::Server
|
|
166
|
-
# @see Hanami::Environment#config
|
|
167
|
-
#
|
|
168
|
-
# @api private
|
|
169
|
-
#
|
|
170
|
-
# @example Define ENV variables from .env
|
|
171
|
-
#
|
|
172
|
-
# # % tree .
|
|
173
|
-
# # .
|
|
174
|
-
# # # ...
|
|
175
|
-
# # ├── .env.test
|
|
176
|
-
# # └── .env.development
|
|
177
|
-
#
|
|
178
|
-
# # % cat .env.test
|
|
179
|
-
# # FOO="bar"
|
|
180
|
-
# # XYZ="yes"
|
|
181
|
-
#
|
|
182
|
-
# # % cat .env.development
|
|
183
|
-
# # FOO="ok"
|
|
184
|
-
#
|
|
185
|
-
# require 'hanami/environment'
|
|
186
|
-
#
|
|
187
|
-
# env = Hanami::Environment.new
|
|
188
|
-
# env.environment # => "development"
|
|
189
|
-
#
|
|
190
|
-
# # Framework defined ENV vars
|
|
191
|
-
# ENV['HANAMI_ENV'] # => "development"
|
|
192
|
-
# ENV['RACK_ENV'] # => "development"
|
|
193
|
-
#
|
|
194
|
-
# ENV['HANAMI_HOST'] # => "localhost"
|
|
195
|
-
# ENV['HANAMI_PORT'] # => "2300"
|
|
196
|
-
#
|
|
197
|
-
# # User defined ENV vars
|
|
198
|
-
# ENV['FOO'] # => "ok"
|
|
199
|
-
# ENV['XYZ'] # => nil
|
|
200
|
-
#
|
|
201
|
-
# # Hanami::Environment evaluates `.env.development` because the current
|
|
202
|
-
# # environment is "development".
|
|
203
|
-
# # Variables declared on `.env.development` will not override
|
|
204
|
-
# # any variable declared on the shell when calling a `hanami` command.
|
|
205
|
-
# # Eg. In `FOO="not ok" bundle exec hanami c` `FOO` will not be overwritten
|
|
206
|
-
# # to `"ok"`.
|
|
207
|
-
def initialize(options = {})
|
|
208
|
-
opts = options.to_h.dup
|
|
209
|
-
@env = Hanami::Env.new(env: opts.delete(:env) || ENV)
|
|
210
|
-
@options = Hanami::Hanamirc.new(root).options
|
|
211
|
-
@options.merge! Utils::Hash.symbolize(opts.clone)
|
|
212
|
-
LOCK.synchronize { set_env_vars! }
|
|
213
|
-
end
|
|
214
|
-
|
|
215
|
-
# The current environment
|
|
216
|
-
#
|
|
217
|
-
# In order to decide the value, it looks up to the following `ENV` vars:
|
|
218
|
-
#
|
|
219
|
-
# * HANAMI_ENV
|
|
220
|
-
# * RACK_ENV
|
|
221
|
-
#
|
|
222
|
-
# If those are missing it falls back to the default one: `"development"`.
|
|
223
|
-
#
|
|
224
|
-
# Rack environment `"deployment"` is translated to Hanami `"production"`.
|
|
225
|
-
#
|
|
226
|
-
# @return [String] the current environment
|
|
227
|
-
#
|
|
228
|
-
# @since 0.1.0
|
|
229
|
-
# @api private
|
|
230
|
-
#
|
|
231
|
-
# @see Hanami::Environment::DEFAULT_ENV
|
|
232
|
-
def environment
|
|
233
|
-
@environment ||= env[HANAMI_ENV] || rack_env || DEFAULT_ENV
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
# @since 0.3.1
|
|
237
|
-
# @api private
|
|
238
|
-
#
|
|
239
|
-
# @see Hanami.env?(name)
|
|
240
|
-
def environment?(*names)
|
|
241
|
-
names.map(&:to_s).include?(environment)
|
|
242
|
-
end
|
|
243
|
-
|
|
244
|
-
# A set of Bundler groups
|
|
245
|
-
#
|
|
246
|
-
# @return [Array] A set of groups
|
|
247
|
-
#
|
|
248
|
-
# @since 0.2.0
|
|
249
|
-
# @api private
|
|
250
|
-
#
|
|
251
|
-
# @see http://bundler.io/v1.7/groups.html
|
|
252
|
-
def bundler_groups
|
|
253
|
-
[:default, environment]
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
# Project name
|
|
257
|
-
#
|
|
258
|
-
# @return [String] Project name
|
|
259
|
-
#
|
|
260
|
-
# @since 0.8.0
|
|
261
|
-
# @api private
|
|
262
|
-
def project_name
|
|
263
|
-
@options.fetch(:project)
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
# Application's root
|
|
267
|
-
#
|
|
268
|
-
# It defaults to the current working directory.
|
|
269
|
-
# Hanami assumes that all the commands are executed from there.
|
|
270
|
-
#
|
|
271
|
-
# @return [Pathname] application's root
|
|
272
|
-
#
|
|
273
|
-
# @since 0.2.0
|
|
274
|
-
# @api private
|
|
275
|
-
def root
|
|
276
|
-
@root ||= Pathname.new(Dir.pwd)
|
|
277
|
-
end
|
|
278
|
-
|
|
279
|
-
# Application's config directory
|
|
280
|
-
#
|
|
281
|
-
# It's the application where all the configurations are stored.
|
|
282
|
-
#
|
|
283
|
-
# In order to decide the value, it looks up the following sources:
|
|
284
|
-
#
|
|
285
|
-
# * CLI option `config`
|
|
286
|
-
#
|
|
287
|
-
# If those are missing it falls back to the default one: `"config/"`.
|
|
288
|
-
#
|
|
289
|
-
# When a relative path is given via CLI option, it assumes to be located
|
|
290
|
-
# under application's root. If absolute path, it will be used as it is.
|
|
291
|
-
#
|
|
292
|
-
# @return [Pathname] the config directory
|
|
293
|
-
#
|
|
294
|
-
# @since 0.2.0
|
|
295
|
-
# @api private
|
|
296
|
-
#
|
|
297
|
-
# @see Hanami::Environment::DEFAULT_CONFIG
|
|
298
|
-
# @see Hanami::Environment#root
|
|
299
|
-
def config
|
|
300
|
-
@config ||= root.join(@options.fetch(:config) { DEFAULT_CONFIG })
|
|
301
|
-
end
|
|
302
|
-
|
|
303
|
-
# The HTTP host name
|
|
304
|
-
#
|
|
305
|
-
# In order to decide the value, it looks up the following sources:
|
|
306
|
-
#
|
|
307
|
-
# * CLI option `host`
|
|
308
|
-
# * HANAMI_HOST ENV var
|
|
309
|
-
#
|
|
310
|
-
# If those are missing it falls back to the following defaults:
|
|
311
|
-
#
|
|
312
|
-
# * `"localhost"` for development
|
|
313
|
-
# * `"0.0.0.0"` for all the other environments
|
|
314
|
-
#
|
|
315
|
-
# @return [String] the HTTP host name
|
|
316
|
-
#
|
|
317
|
-
# @since 0.1.0
|
|
318
|
-
# @api private
|
|
319
|
-
#
|
|
320
|
-
# @see Hanami::Environment::DEFAULT_HOST
|
|
321
|
-
# @see Hanami::Environment::LISTEN_ALL_HOST
|
|
322
|
-
def host
|
|
323
|
-
@host ||= @options.fetch(:host) do
|
|
324
|
-
env[HANAMI_HOST] || default_host
|
|
325
|
-
end
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
# The HTTP port
|
|
329
|
-
#
|
|
330
|
-
# In order to decide the value, it looks up the following sources:
|
|
331
|
-
#
|
|
332
|
-
# * CLI option `port`
|
|
333
|
-
# * HANAMI_PORT ENV var
|
|
334
|
-
#
|
|
335
|
-
# If those are missing it falls back to the default one: `2300`.
|
|
336
|
-
#
|
|
337
|
-
# @return [Integer] the default port
|
|
338
|
-
#
|
|
339
|
-
# @since 0.1.0
|
|
340
|
-
# @api private
|
|
341
|
-
#
|
|
342
|
-
# @see Hanami::Environment::DEFAULT_PORT
|
|
343
|
-
def port
|
|
344
|
-
@port ||= @options.fetch(:port) do
|
|
345
|
-
env[HANAMI_PORT] || DEFAULT_PORT
|
|
346
|
-
end.to_i
|
|
347
|
-
end
|
|
348
|
-
|
|
349
|
-
# Check if the current port is the default one
|
|
350
|
-
#
|
|
351
|
-
# @since 1.0.0
|
|
352
|
-
# @api private
|
|
353
|
-
#
|
|
354
|
-
# @see Hanami::ApplicationConfiguration#port
|
|
355
|
-
def default_port?
|
|
356
|
-
port == DEFAULT_PORT
|
|
357
|
-
end
|
|
358
|
-
|
|
359
|
-
# Path to the Rack configuration file
|
|
360
|
-
#
|
|
361
|
-
# In order to decide the value, it looks up the following sources:
|
|
362
|
-
#
|
|
363
|
-
# * CLI option `rackup`
|
|
364
|
-
#
|
|
365
|
-
# If those are missing it falls back to the default one: `"config.ru"`.
|
|
366
|
-
#
|
|
367
|
-
# When a relative path is given via CLI option, it assumes to be located
|
|
368
|
-
# under application's root. If absolute path, it will be used as it is.
|
|
369
|
-
#
|
|
370
|
-
# @return [Pathname] path to the Rack configuration file
|
|
371
|
-
#
|
|
372
|
-
# @since 0.2.0
|
|
373
|
-
# @api private
|
|
374
|
-
def rackup
|
|
375
|
-
root.join(@options.fetch(:rackup) { DEFAULT_RACKUP })
|
|
376
|
-
end
|
|
377
|
-
|
|
378
|
-
# Path to environment configuration file.
|
|
379
|
-
#
|
|
380
|
-
# In order to decide the value, it looks up the following sources:
|
|
381
|
-
#
|
|
382
|
-
# * CLI option `environment`
|
|
383
|
-
#
|
|
384
|
-
# If those are missing it falls back to the default one:
|
|
385
|
-
# `"config/environment.rb"`.
|
|
386
|
-
#
|
|
387
|
-
# When a relative path is given via CLI option, it assumes to be located
|
|
388
|
-
# under application's root. If absolute path, it will be used as it is.
|
|
389
|
-
#
|
|
390
|
-
# @return [Pathname] path to applications
|
|
391
|
-
#
|
|
392
|
-
# @since 0.1.0
|
|
393
|
-
# @api private
|
|
394
|
-
#
|
|
395
|
-
# @see Hanami::Environment::DEFAULT_ENVIRONMENT_CONFIG
|
|
396
|
-
def env_config
|
|
397
|
-
root.join("config", "environment.rb")
|
|
398
|
-
end
|
|
399
|
-
|
|
400
|
-
alias project_environment_configuration env_config
|
|
401
|
-
|
|
402
|
-
# Require application environment
|
|
403
|
-
#
|
|
404
|
-
# Eg <tt>require "config/environment"</tt>.
|
|
405
|
-
#
|
|
406
|
-
# @since 0.4.0
|
|
407
|
-
# @api private
|
|
408
|
-
def require_application_environment
|
|
409
|
-
::Bundler.setup(*bundler_groups)
|
|
410
|
-
require project_environment_configuration.to_s # if project_environment_configuration.exist?
|
|
411
|
-
end
|
|
412
|
-
|
|
413
|
-
# @api private
|
|
414
|
-
alias require_project_environment require_application_environment
|
|
415
|
-
|
|
416
|
-
# Determine if activate code reloading for the current environment while
|
|
417
|
-
# running the server.
|
|
418
|
-
#
|
|
419
|
-
# In order to decide the value, it looks up the following sources:
|
|
420
|
-
#
|
|
421
|
-
# * CLI option `code_reloading`
|
|
422
|
-
#
|
|
423
|
-
# If those are missing it falls back to the following defaults:
|
|
424
|
-
#
|
|
425
|
-
# * true for development
|
|
426
|
-
# * false for all the other environments
|
|
427
|
-
#
|
|
428
|
-
# @return [TrueClass,FalseClass] the result of the check
|
|
429
|
-
#
|
|
430
|
-
# @since 0.2.0
|
|
431
|
-
# @api private
|
|
432
|
-
#
|
|
433
|
-
# @see Hanami::Commands::Server
|
|
434
|
-
# @see Hanami::Environment::CODE_RELOADING
|
|
435
|
-
def code_reloading?
|
|
436
|
-
@options.fetch(:code_reloading) { !!CODE_RELOADING[environment] }
|
|
437
|
-
end
|
|
438
|
-
|
|
439
|
-
# @since 0.6.0
|
|
440
|
-
# @api private
|
|
441
|
-
def serve_static_assets?
|
|
442
|
-
SERVE_STATIC_ASSETS_ENABLED == env[SERVE_STATIC_ASSETS]
|
|
443
|
-
end
|
|
444
|
-
|
|
445
|
-
# @since 0.6.0
|
|
446
|
-
# @api private
|
|
447
|
-
def static_assets_middleware
|
|
448
|
-
return unless serve_static_assets?
|
|
449
|
-
|
|
450
|
-
if environment?(:development, :test)
|
|
451
|
-
require 'hanami/assets/static'
|
|
452
|
-
Hanami::Assets::Static
|
|
453
|
-
else
|
|
454
|
-
require 'hanami/static'
|
|
455
|
-
Hanami::Static
|
|
456
|
-
end
|
|
457
|
-
end
|
|
458
|
-
|
|
459
|
-
# @since 0.4.0
|
|
460
|
-
# @api private
|
|
461
|
-
def apps_path
|
|
462
|
-
@options.fetch(:path, APPS_PATH)
|
|
463
|
-
end
|
|
464
|
-
|
|
465
|
-
# Serialize the most relevant settings into a Hash
|
|
466
|
-
#
|
|
467
|
-
# @return [::Hash]
|
|
468
|
-
#
|
|
469
|
-
# @since 0.1.0
|
|
470
|
-
# @api private
|
|
471
|
-
def to_options
|
|
472
|
-
@options.merge(
|
|
473
|
-
environment: environment,
|
|
474
|
-
env_config: env_config,
|
|
475
|
-
apps_path: apps_path,
|
|
476
|
-
rackup: rackup,
|
|
477
|
-
host: host,
|
|
478
|
-
port: port
|
|
479
|
-
)
|
|
480
|
-
end
|
|
481
|
-
|
|
482
|
-
private
|
|
483
|
-
|
|
484
|
-
# @api private
|
|
485
|
-
attr_reader :env
|
|
486
|
-
|
|
487
|
-
# @since 0.1.0
|
|
488
|
-
# @api private
|
|
489
|
-
def set_env_vars!
|
|
490
|
-
set_application_env_vars!
|
|
491
|
-
set_hanami_env_vars!
|
|
492
|
-
end
|
|
493
|
-
|
|
494
|
-
# @since 0.2.0
|
|
495
|
-
# @api private
|
|
496
|
-
def set_hanami_env_vars!
|
|
497
|
-
env[HANAMI_ENV] = env[RACK_ENV] = environment
|
|
498
|
-
env[HANAMI_HOST] = host
|
|
499
|
-
env[HANAMI_PORT] = port.to_s
|
|
500
|
-
end
|
|
501
|
-
|
|
502
|
-
# @since 0.2.0
|
|
503
|
-
# @api private
|
|
504
|
-
def set_application_env_vars!
|
|
505
|
-
DOTENV_FILES.each do |filename_format|
|
|
506
|
-
file = filename_format % { environment: environment }
|
|
507
|
-
next unless dotenv_applicable?(file)
|
|
508
|
-
|
|
509
|
-
path = root.join(file)
|
|
510
|
-
env.load!(path) if path.exist?
|
|
511
|
-
end
|
|
512
|
-
end
|
|
513
|
-
|
|
514
|
-
# @since 0.1.0
|
|
515
|
-
# @api private
|
|
516
|
-
def default_host
|
|
517
|
-
environment == DEFAULT_ENV ? DEFAULT_HOST : LISTEN_ALL_HOST
|
|
518
|
-
end
|
|
519
|
-
|
|
520
|
-
# @since 0.6.0
|
|
521
|
-
# @api private
|
|
522
|
-
def rack_env
|
|
523
|
-
case env[RACK_ENV]
|
|
524
|
-
when RACK_ENV_DEPLOYMENT
|
|
525
|
-
PRODUCTION_ENV
|
|
526
|
-
else
|
|
527
|
-
env[RACK_ENV]
|
|
528
|
-
end
|
|
529
|
-
end
|
|
530
|
-
|
|
531
|
-
# @api private
|
|
532
|
-
# @since 1.3.3
|
|
533
|
-
#
|
|
534
|
-
# @see https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
|
535
|
-
def dotenv_applicable?(file)
|
|
536
|
-
return false if file == DOTENV_LOCAL_FILE && environment == TEST_ENV
|
|
537
|
-
|
|
538
|
-
true
|
|
539
|
-
end
|
|
540
|
-
end
|
|
541
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
module Hanami
|
|
2
|
-
# @api private
|
|
3
|
-
class EnvironmentApplicationConfigurations
|
|
4
|
-
# @api private
|
|
5
|
-
ALL = :all
|
|
6
|
-
|
|
7
|
-
# @api private
|
|
8
|
-
def initialize
|
|
9
|
-
@configurations = Concurrent::Hash.new { |k, v| k[v] = [] }
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
# @api private
|
|
13
|
-
def add(environment, &blk)
|
|
14
|
-
env = (environment || ALL).to_sym
|
|
15
|
-
configurations[env].push(blk)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
# @api private
|
|
19
|
-
def each(environment, &blk)
|
|
20
|
-
configurations.each do |env, blks|
|
|
21
|
-
next unless matching_env?(environment, env)
|
|
22
|
-
blks.each(&blk)
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
# @api private
|
|
29
|
-
attr_reader :configurations
|
|
30
|
-
|
|
31
|
-
# @api private
|
|
32
|
-
def matching_env?(environment, env)
|
|
33
|
-
environment.to_sym == env ||
|
|
34
|
-
env == ALL
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|