hanami 1.3.3 → 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 +46 -22
- data/FEATURES.md +1 -7
- data/LICENSE.md +1 -1
- data/README.md +1 -1
- data/bin/hanami +5 -3
- data/hanami.gemspec +24 -28
- data/lib/hanami.rb +39 -243
- data/lib/hanami/application.rb +44 -176
- data/lib/hanami/boot.rb +6 -0
- data/lib/hanami/cli/commands.rb +4 -41
- data/lib/hanami/cli/commands/command.rb +16 -26
- data/lib/hanami/cli/commands/server.rb +63 -14
- data/lib/hanami/configuration.rb +181 -191
- 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/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
- metadata +34 -222
- 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 -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/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 -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 -95
- 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
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1c197523a333228ef0596099b121a0f3a3e02c4a5a0da3f3f4fe837e794b7cf8
|
|
4
|
+
data.tar.gz: 5a7526ef47fc6f64ebffdae725d26a17944e390274dbc478ff52d593c7ba63b9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: dd55bf77935140473affae77676eae8afe042f385dee3288dd9d80729fb887899f89950f26b83e2b793161545347cdc3dab8a5f6e0915013aa333c2caf2e080d
|
|
7
|
+
data.tar.gz: d254599b55640e0e3a27b718c1ae7141a40662c7291e60463d9620383cc419d49f06f5c8d1712b484f50ba758b71bf3f0ae79729452243532a0769e00478af8b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,30 +1,54 @@
|
|
|
1
1
|
# Hanami
|
|
2
2
|
The web, with simplicity.
|
|
3
3
|
|
|
4
|
-
##
|
|
4
|
+
## v2.0.0.alpha1 - 2019-01-30
|
|
5
5
|
### Added
|
|
6
|
-
- [
|
|
6
|
+
- [Luca Guidi] Implemented from scratch `hanami version`
|
|
7
|
+
- [Luca Guidi] Implemented from scratch `hanami server`
|
|
8
|
+
- [Luca Guidi] Main configuration is opinionated: when a setting is not specified in generated code, it uses a framework default.
|
|
9
|
+
- [Luca Guidi] Main configuration setting `environment`: to yield env based settings (e.g. `config.environment(:production) { |c| c.logger = {...} }`)
|
|
10
|
+
- [Luca Guidi] Main configuration setting `base_url`: to set the base URL of the app (e.g. `config.base_url = "https://example.com"`)
|
|
11
|
+
- [Luca Guidi] Main configuration setting `logger`: to set the logger options (e.g. `config.logger = { level: :info, format: :json }`)
|
|
12
|
+
- [Luca Guidi] Main configuration setting `routes`: to set the path to routes file (e.g. `config.routes = "path/to/routes"`)
|
|
13
|
+
- [Luca Guidi] Main configuration setting `cookies`: to set cookies options (e.g. `config.cookies = { max_age: 300 }`)
|
|
14
|
+
- [Luca Guidi] Main configuration setting `sessions`: to set session options (e.g. `config.sessions = :cookie, { secret: "abc" }`)
|
|
15
|
+
- [Luca Guidi] Main configuration setting `default_request_format`: to set the fallback for request format (aka MIME Type) (e.g. `config.default_request_format = :json`)
|
|
16
|
+
- [Luca Guidi] Main configuration setting `default_response_format`: to set the default response format (aka MIME Type) (e.g. `config.default_response_format = :json`)
|
|
17
|
+
- [Luca Guidi] Main configuration setting `middleware` to mount Rack middleware (e.g. `config.middleware.use MyMiddleware, "argument"`)
|
|
18
|
+
- [Luca Guidi] Main configuration setting `security` to set security settings (see below)
|
|
19
|
+
- [Luca Guidi] Main configuration setting `inflections` to configure inflections (e.g. `config.inflections { |i| i.plural "virus", "viruses" }`)
|
|
20
|
+
- [Luca Guidi] Main configuration security setting `x_frame_options`: defaults to `"deny"` (e.g. `config.security.x_frame_options = "sameorigin"`)
|
|
21
|
+
- [Luca Guidi] Main configuration security setting `x_content_type_options`: defaults to `"nosniff"` (e.g. `config.security.x_content_type_options = nil`)
|
|
22
|
+
- [Luca Guidi] Main configuration security setting `x_xss_protection`: defaults to `"1; mode=block"` (e.g. `config.security.x_xss_protection = "1"`)
|
|
23
|
+
- [Luca Guidi] Main configuration security setting `content_security_policy`: defaults to `"form-action 'self'; frame-ancestors 'self'; base-uri 'self'; default-src 'none'; script-src 'self'; connect-src 'self'; img-src 'self' https: data:; style-src 'self' 'unsafe-inline' https:; font-src 'self'; object-src 'none'; plugin-types application/pdf; child-src 'self'; frame-src 'self'; media-src 'self'"`
|
|
24
|
+
(e.g. `config.security.content_security_policy[:style_src] += " https://my.cdn.example"` to add another source)
|
|
25
|
+
(e.g. `config.security.content_security_policy[:plugin_types] = nil` to override the settings)
|
|
7
26
|
|
|
8
|
-
###
|
|
9
|
-
- [
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
- [Luca Guidi]
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
- [
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
27
|
+
### Changed
|
|
28
|
+
- [Luca Guidi] Drop support for Ruby: MRI 2.3, and 2.4.
|
|
29
|
+
- [Luca Guidi] `Hanami::Application` must be used as superclass for main application under `config/application.rb` (e.g. `Bookshelf::Application`)
|
|
30
|
+
- [Luca Guidi] Main configuration is available at `config/application.rb` instead of `config/enviroment.rb`
|
|
31
|
+
- [Luca Guidi] Removed `Hanami.configure` in favor of main application configuration (e.g. `Bookshelf::Application.config`)
|
|
32
|
+
- [Luca Guidi] Removed DSL syntax for main configuration (from `cookies max_age: 600` to `config.cookies = { max_age: 600 }`)
|
|
33
|
+
- [Luca Guidi] Per enviroment settings must be wrapped in a block (e.g. `config.enviroment(:production) { |c| c.logger = {} }`)
|
|
34
|
+
- [Luca Guidi] Concrete applications are no longer supported (e.g. `Web::Application` in `apps/web/application.rb`)
|
|
35
|
+
- [Luca Guidi] Main routes must be configured at `config/routes.rb`:
|
|
36
|
+
```ruby
|
|
37
|
+
# frozen_string_literal: true
|
|
38
|
+
|
|
39
|
+
Hanami.application.routes do
|
|
40
|
+
mount :web, at: "/" do
|
|
41
|
+
root to: "home#index"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
mount :admin, at: "/admin" do
|
|
45
|
+
root to: "home#index"
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
```
|
|
49
|
+
- [Luca Guidi] Per application routes are no longer supported (e.g. `apps/web/config/routes.rb`)
|
|
50
|
+
- [Luca Guidi] Removed `shotgun` and code reloading from the core. Code reloading is implemented by `hanami-reloader` gem.
|
|
51
|
+
- [Luca Guidi] Removed support for `.hanamirc`
|
|
28
52
|
|
|
29
53
|
## v1.3.0 - 2018-10-24
|
|
30
54
|
### Added
|
data/FEATURES.md
CHANGED
|
@@ -3,13 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
## Features
|
|
5
5
|
|
|
6
|
-
##
|
|
7
|
-
|
|
8
|
-
- Standardize file loading for `.env` files (see: https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use)
|
|
9
|
-
|
|
10
|
-
## v1.3.2 - 2019-07-26
|
|
11
|
-
|
|
12
|
-
## v1.3.1 - 2019-01-18
|
|
6
|
+
## v2.0.0.alpha1 - 2019-01-30
|
|
13
7
|
|
|
14
8
|
## v1.3.0 - 2018-10-24
|
|
15
9
|
|
data/LICENSE.md
CHANGED
data/README.md
CHANGED
data/bin/hanami
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env ruby
|
|
2
|
-
|
|
3
|
-
require 'hanami/cli/commands'
|
|
2
|
+
# frozen_string_literal: true
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
require "bundler"
|
|
5
|
+
require "hanami/cli/commands"
|
|
6
|
+
|
|
7
|
+
Bundler.require(*Hanami.bundler_groups) if File.exist?(ENV["BUNDLE_GEMFILE"] || "Gemfile")
|
|
6
8
|
Hanami::CLI.new(Hanami::CLI::Commands).call
|
data/hanami.gemspec
CHANGED
|
@@ -1,40 +1,36 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
-
require
|
|
5
|
+
require "hanami/version"
|
|
5
6
|
|
|
6
7
|
Gem::Specification.new do |spec|
|
|
7
|
-
spec.name =
|
|
8
|
+
spec.name = "hanami"
|
|
8
9
|
spec.version = Hanami::VERSION
|
|
9
|
-
spec.authors = [
|
|
10
|
-
spec.email = [
|
|
11
|
-
spec.summary =
|
|
12
|
-
spec.description =
|
|
13
|
-
spec.homepage =
|
|
14
|
-
spec.license =
|
|
10
|
+
spec.authors = ["Luca Guidi"]
|
|
11
|
+
spec.email = ["me@lucaguidi.com"]
|
|
12
|
+
spec.summary = "The web, with simplicity"
|
|
13
|
+
spec.description = "Hanami is a web framework for Ruby"
|
|
14
|
+
spec.homepage = "http://hanamirb.org"
|
|
15
|
+
spec.license = "MIT"
|
|
15
16
|
|
|
16
17
|
spec.files = `git ls-files -c -o --exclude-standard -z -- lib/* bin/* LICENSE.md README.md CODE_OF_CONDUCT.md CHANGELOG.md FEATURES.md hanami.gemspec`.split("\x0")
|
|
17
18
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
19
|
spec.test_files = spec.files.grep(%r{^(test)/})
|
|
19
|
-
spec.require_paths = [
|
|
20
|
-
spec.required_ruby_version =
|
|
20
|
+
spec.require_paths = ["lib"]
|
|
21
|
+
spec.required_ruby_version = ">= 2.5.0"
|
|
21
22
|
|
|
22
|
-
spec.metadata[
|
|
23
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
23
24
|
|
|
24
|
-
spec.add_dependency
|
|
25
|
-
spec.add_dependency
|
|
26
|
-
spec.add_dependency
|
|
27
|
-
spec.add_dependency
|
|
28
|
-
spec.add_dependency
|
|
29
|
-
spec.add_dependency
|
|
30
|
-
spec.add_dependency
|
|
31
|
-
spec.add_dependency 'hanami-assets', '~> 1.3'
|
|
32
|
-
spec.add_dependency 'hanami-cli', '~> 0.3'
|
|
33
|
-
spec.add_dependency 'concurrent-ruby', '~> 1.0'
|
|
34
|
-
spec.add_dependency 'bundler', '>= 1.6', '< 3'
|
|
25
|
+
spec.add_dependency "hanami-utils", "~> 2.0.alpha"
|
|
26
|
+
spec.add_dependency "hanami-router", "~> 2.0.alpha"
|
|
27
|
+
spec.add_dependency "hanami-controller", "~> 2.0.alpha"
|
|
28
|
+
spec.add_dependency "hanami-cli", "~> 1.0.alpha"
|
|
29
|
+
spec.add_dependency "dry-system", "~> 0.10"
|
|
30
|
+
spec.add_dependency "dry-inflector", "~> 0.1", ">= 0.1.2"
|
|
31
|
+
spec.add_dependency "bundler", ">= 1.16", "< 3"
|
|
35
32
|
|
|
36
|
-
spec.add_development_dependency
|
|
37
|
-
spec.add_development_dependency
|
|
38
|
-
spec.add_development_dependency
|
|
39
|
-
spec.add_development_dependency 'rake', '~> 12.0'
|
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.8"
|
|
34
|
+
spec.add_development_dependency "rack-test", "~> 1.1"
|
|
35
|
+
spec.add_development_dependency "rake", "~> 12.0"
|
|
40
36
|
end
|
data/lib/hanami.rb
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# A complete web framework for Ruby
|
|
4
4
|
#
|
|
@@ -6,277 +6,73 @@ require 'thread'
|
|
|
6
6
|
#
|
|
7
7
|
# @see http://hanamirb.org
|
|
8
8
|
module Hanami
|
|
9
|
-
require
|
|
10
|
-
require
|
|
11
|
-
require
|
|
12
|
-
require
|
|
13
|
-
require 'hanami/application'
|
|
14
|
-
require 'hanami/components'
|
|
15
|
-
require 'hanami/configuration'
|
|
9
|
+
require "hanami/version"
|
|
10
|
+
require "hanami/frameworks"
|
|
11
|
+
require "hanami/container"
|
|
12
|
+
require "hanami/application"
|
|
16
13
|
|
|
17
|
-
# @api private
|
|
18
|
-
# @since 0.6.0
|
|
19
|
-
DEFAULT_PUBLIC_DIRECTORY = 'public'.freeze
|
|
20
|
-
|
|
21
|
-
# @api private
|
|
22
|
-
# @since 0.9.0
|
|
23
14
|
@_mutex = Mutex.new
|
|
24
|
-
@_plugins = Concurrent::Array.new
|
|
25
15
|
|
|
26
|
-
|
|
27
|
-
#
|
|
28
|
-
# Please note that the code for this method is generated by `hanami new`.
|
|
29
|
-
#
|
|
30
|
-
# @param blk [Proc] the configuration block
|
|
31
|
-
#
|
|
32
|
-
# @since 0.9.0
|
|
33
|
-
#
|
|
34
|
-
# @example
|
|
35
|
-
# # config/environment.rb
|
|
36
|
-
#
|
|
37
|
-
# # ...
|
|
38
|
-
#
|
|
39
|
-
# Hanami.configure do
|
|
40
|
-
# mount Admin::Application, at: "/admin"
|
|
41
|
-
# mount Web::Application, at: "/"
|
|
42
|
-
#
|
|
43
|
-
# model do
|
|
44
|
-
# adapter :sql, ENV['DATABASE_URL']
|
|
45
|
-
#
|
|
46
|
-
# migrations "db/migrations"
|
|
47
|
-
# schema "db/schema.sql"
|
|
48
|
-
# end
|
|
49
|
-
#
|
|
50
|
-
# mailer do
|
|
51
|
-
# root "lib/bookshelf/mailers"
|
|
52
|
-
#
|
|
53
|
-
# delivery do
|
|
54
|
-
# development :test
|
|
55
|
-
# test :test
|
|
56
|
-
# # production :smtp, address: ENV['SMTP_HOST'], port: ENV['SMTP_PORT']
|
|
57
|
-
# end
|
|
58
|
-
# end
|
|
59
|
-
# end
|
|
60
|
-
def self.configure(&blk)
|
|
16
|
+
def self.application
|
|
61
17
|
@_mutex.synchronize do
|
|
62
|
-
|
|
63
|
-
end
|
|
64
|
-
end
|
|
18
|
+
raise "Hanami application not configured" unless defined?(@_application)
|
|
65
19
|
|
|
66
|
-
|
|
67
|
-
#
|
|
68
|
-
# @return [Hanami::Configuration] the configuration
|
|
69
|
-
#
|
|
70
|
-
# @see Hanami.configure
|
|
71
|
-
#
|
|
72
|
-
# @since 0.9.0
|
|
73
|
-
# @api private
|
|
74
|
-
def self.configuration
|
|
75
|
-
@_mutex.synchronize do
|
|
76
|
-
raise "Hanami not configured" unless defined?(@_configuration)
|
|
77
|
-
@_configuration
|
|
20
|
+
@_application
|
|
78
21
|
end
|
|
79
22
|
end
|
|
80
23
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
#
|
|
85
|
-
# @since 1.2.0
|
|
86
|
-
def self.plugin(&blk)
|
|
87
|
-
@_plugins << blk
|
|
88
|
-
end
|
|
89
|
-
|
|
90
|
-
# Plugins registry
|
|
91
|
-
#
|
|
92
|
-
# NOTE: We can't use `Components` registry.
|
|
93
|
-
#
|
|
94
|
-
# Plugins are loaded when Bundler requires `Gemfile` gems.
|
|
95
|
-
# During this phase the `Components` that we can resolve are erased by the
|
|
96
|
-
# first incoming request in development.
|
|
97
|
-
# They are erased by a workaround that we had to put in place in `Hanami.boot`.
|
|
98
|
-
# This workaround is `Components.release` and it was introduced because
|
|
99
|
-
# `shotgun` failed to reload components, so we have to release for each
|
|
100
|
-
# incoming request.
|
|
101
|
-
# After the `Components` registry is cleared up, Hanami is able to resolve all
|
|
102
|
-
# the components from scratch.
|
|
103
|
-
#
|
|
104
|
-
# When we'll switch to `hanami-reloader` for development, we can remove
|
|
105
|
-
# `Components.release` and we'll be able to store plugins in `Components` and
|
|
106
|
-
# remove `Hanami.plugins` as well.
|
|
107
|
-
#
|
|
108
|
-
# @since 1.2.0
|
|
109
|
-
# @api private
|
|
110
|
-
def self.plugins
|
|
111
|
-
@_plugins
|
|
112
|
-
end
|
|
24
|
+
def self.application=(app)
|
|
25
|
+
@_mutex.synchronize do
|
|
26
|
+
raise "Hanami application already configured" if defined?(@_application)
|
|
113
27
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
# NOTE: In case this is invoked many times, it guarantees that the boot
|
|
117
|
-
# process happens only once.
|
|
118
|
-
#
|
|
119
|
-
# NOTE: This MUST NOT be wrapped by a Mutex, because it would cause a deadlock.
|
|
120
|
-
#
|
|
121
|
-
# @return [NilClass]
|
|
122
|
-
#
|
|
123
|
-
# @since 0.9.0
|
|
124
|
-
def self.boot
|
|
125
|
-
Components.release if code_reloading?
|
|
126
|
-
Components.resolve('all')
|
|
127
|
-
Hanami::Model.disconnect if defined?(Hanami::Model)
|
|
128
|
-
nil
|
|
28
|
+
@_application = app unless app.name.nil?
|
|
29
|
+
end
|
|
129
30
|
end
|
|
130
31
|
|
|
131
|
-
# Main application that mounts many Rack and/or Hanami applications.
|
|
132
|
-
#
|
|
133
|
-
# This is used as integration point for:
|
|
134
|
-
#
|
|
135
|
-
# * `config.ru` (`run Hanami.app`)
|
|
136
|
-
# * Feature tests (`Capybara.app = Hanami.app`)
|
|
137
|
-
#
|
|
138
|
-
#
|
|
139
|
-
#
|
|
140
|
-
# It lazily loads your Hanami project, in case it wasn't booted on before.
|
|
141
|
-
# This is the case when `hanami server` isn't invoked, but we use different
|
|
142
|
-
# ways to run the project (eg. `rackup`).
|
|
143
|
-
#
|
|
144
|
-
# @return [Hanami::App] the app
|
|
145
|
-
#
|
|
146
|
-
# @since 0.9.0
|
|
147
|
-
# @api private
|
|
148
|
-
#
|
|
149
|
-
# @see Hanami.boot
|
|
150
32
|
def self.app
|
|
151
|
-
|
|
152
|
-
|
|
33
|
+
@_mutex.synchronize do
|
|
34
|
+
raise "Hanami.app not configured" unless defined?(@_app)
|
|
35
|
+
|
|
36
|
+
@_app
|
|
37
|
+
end
|
|
153
38
|
end
|
|
154
39
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
# env variable. If the HANAMI_APPS env variable is not set, it defaults
|
|
159
|
-
# to loading all applications.
|
|
160
|
-
#
|
|
161
|
-
# @return [TrueClass,FalseClass] the result of the check
|
|
162
|
-
#
|
|
163
|
-
# @since 1.1.0
|
|
164
|
-
#
|
|
165
|
-
# @example
|
|
166
|
-
#
|
|
167
|
-
# # Mount hanami app for specific app
|
|
168
|
-
# Hanami.configure do
|
|
169
|
-
# if Hanami.app?(:web)
|
|
170
|
-
# require_relative '../apps/web/application'
|
|
171
|
-
# mount Web::Application, at: '/'
|
|
172
|
-
# end
|
|
173
|
-
# end
|
|
174
|
-
#
|
|
175
|
-
def self.app?(app)
|
|
176
|
-
return true unless ENV.key?('HANAMI_APPS')
|
|
40
|
+
def self.app=(app)
|
|
41
|
+
@_mutex.synchronize do
|
|
42
|
+
raise "Hanami.app already configured" if defined?(@_app)
|
|
177
43
|
|
|
178
|
-
|
|
179
|
-
|
|
44
|
+
@_app = app
|
|
45
|
+
end
|
|
180
46
|
end
|
|
181
47
|
|
|
182
|
-
# Return root of the project (top level directory).
|
|
183
|
-
#
|
|
184
|
-
# @return [Pathname] root path
|
|
185
|
-
#
|
|
186
|
-
# @since 0.3.2
|
|
187
|
-
#
|
|
188
|
-
# @example
|
|
189
|
-
# Hanami.root # => #<Pathname:/Users/luca/Code/bookshelf>
|
|
190
48
|
def self.root
|
|
191
|
-
|
|
192
|
-
end
|
|
193
|
-
|
|
194
|
-
# Project public directory
|
|
195
|
-
#
|
|
196
|
-
# @return [Pathname] public directory
|
|
197
|
-
#
|
|
198
|
-
# @since 0.6.0
|
|
199
|
-
#
|
|
200
|
-
# @example
|
|
201
|
-
# Hanami.public_directory # => #<Pathname:/Users/luca/Code/bookshelf/public>
|
|
202
|
-
def self.public_directory
|
|
203
|
-
root.join(DEFAULT_PUBLIC_DIRECTORY)
|
|
49
|
+
Container.root
|
|
204
50
|
end
|
|
205
51
|
|
|
206
|
-
# Return the current environment
|
|
207
|
-
#
|
|
208
|
-
# @return [String] the current environment
|
|
209
|
-
#
|
|
210
|
-
# @since 0.3.1
|
|
211
|
-
#
|
|
212
|
-
# @see Hanami::Environment#environment
|
|
213
|
-
#
|
|
214
|
-
# @example
|
|
215
|
-
# Hanami.env => "development"
|
|
216
52
|
def self.env
|
|
217
|
-
|
|
53
|
+
(ENV["HANAMI_ENV"] || "development").to_sym
|
|
218
54
|
end
|
|
219
55
|
|
|
220
|
-
# Check to see if specified environment(s) matches the current environment.
|
|
221
|
-
#
|
|
222
|
-
# If multiple names are given, it returns true, if at least one of them
|
|
223
|
-
# matches the current environment.
|
|
224
|
-
#
|
|
225
|
-
# @return [TrueClass,FalseClass] the result of the check
|
|
226
|
-
#
|
|
227
|
-
# @since 0.3.1
|
|
228
|
-
#
|
|
229
|
-
# @see Hanami.env
|
|
230
|
-
#
|
|
231
|
-
# @example Single name
|
|
232
|
-
# puts ENV['HANAMI_ENV'] # => "development"
|
|
233
|
-
#
|
|
234
|
-
# Hanami.env?(:development) # => true
|
|
235
|
-
# Hanami.env?('development') # => true
|
|
236
|
-
#
|
|
237
|
-
# Hanami.env?(:production) # => false
|
|
238
|
-
#
|
|
239
|
-
# @example Multiple names
|
|
240
|
-
# puts ENV['HANAMI_ENV'] # => "development"
|
|
241
|
-
#
|
|
242
|
-
# Hanami.env?(:development, :test) # => true
|
|
243
|
-
# Hanami.env?(:production, :staging) # => false
|
|
244
56
|
def self.env?(*names)
|
|
245
|
-
|
|
57
|
+
names.map(&:to_sym).include?(env)
|
|
246
58
|
end
|
|
247
59
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
# @return [Hanami::Environment] environment
|
|
251
|
-
#
|
|
252
|
-
# @api private
|
|
253
|
-
# @since 0.3.2
|
|
254
|
-
def self.environment
|
|
255
|
-
Components.resolved('environment') do
|
|
256
|
-
Environment.new
|
|
257
|
-
end
|
|
60
|
+
def self.logger
|
|
61
|
+
Container[:logger]
|
|
258
62
|
end
|
|
259
63
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
environment
|
|
270
|
-
Components.resolve('code_reloading')
|
|
271
|
-
Components['code_reloading']
|
|
64
|
+
def self.boot
|
|
65
|
+
@_mutex.synchronize do
|
|
66
|
+
raise "Hanami application already booted" if defined?(@_booted)
|
|
67
|
+
|
|
68
|
+
@_booted = true
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
Container.finalize!
|
|
72
|
+
self.app = application.new
|
|
272
73
|
end
|
|
273
74
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
# @return [Hanami::Logger] the logger
|
|
277
|
-
#
|
|
278
|
-
# @since 1.0.0
|
|
279
|
-
def self.logger
|
|
280
|
-
Components['logger']
|
|
75
|
+
def self.bundler_groups
|
|
76
|
+
[:plugins]
|
|
281
77
|
end
|
|
282
78
|
end
|