hanami 2.0.0.alpha5 → 2.0.0.alpha7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9c8875d3320057cffe3af1a7bb2ff781cd8ad2145c446fc9e9190d344a4a48e6
4
- data.tar.gz: c003bc2117815e10f2c15f458fb3bc6d94b480dfe9f2ec98e6458804f8a0d06d
3
+ metadata.gz: 8db2d523a265dd089048a2a944ccf8b1d5d46a36d496be5638f4807fe3c451ad
4
+ data.tar.gz: fe510075e1e4d362e6c6419aab0d0b001eb8bf80329d51f7546f9955abf08cf6
5
5
  SHA512:
6
- metadata.gz: 7b133de3c728132ef6255480b10068482d58cf1e2708df395f00cc5981cdccac70cbecdb2c8325cd822298d7c92c0ee0253ab1f8f9d95ddf84b0d6de556e7f3f
7
- data.tar.gz: 42b525e3163e7bb73938b5e2fa444ccc15cc38def3e74225086f0e90bb0d805979e0a88a47703fcc73956d68598260ab366a1c155eb94b7114515b8ffc56671e
6
+ metadata.gz: 1af19f64f99af6997e772e25d49a5e835ea9e8ebac64aaab637fe56a0c91ea1b87d4a13d04b26145b58573d12478bd435183873e4cf7378e2b2046866e9a0fa4
7
+ data.tar.gz: d7be6b435ac445a23ceb616180493c863715dca8a039a81e2ab3af0aa49d60f73806625909dbee05aad4b1bab77b7b77fc6c94600f937cbe7e5af206f67efa82
data/CHANGELOG.md CHANGED
@@ -1,6 +1,147 @@
1
1
  # Hanami
2
2
  The web, with simplicity.
3
3
 
4
+ ## v2.0.0.alpha7.1 - 2020-03-09
5
+
6
+ ## Fixed
7
+ - [Tim Riley] Fixed error creating slice classes when the enclosing module did not already exist
8
+
9
+ ## v2.0.0.alpha7 - 2020-03-08
10
+
11
+ ## Added
12
+ - [Tim Riley] Introduced `Hanami::ApplicationLoadError` and `Hanami::SliceLoadError` exceptions to represent errors encountered during application and slice loading.
13
+ - [Tim Riley] `Hanami::Slice.shutdown` can be used to stop all the providers in a slice
14
+
15
+ ## Changed
16
+ - [Tim Riley] Slices are now represented as concrete classes (such as `Main::Slice`) inheriting from `Hanami::Slice`, as opposed to _instances_ of `Hanami::Slice`. You may create your own definitions for these slices in `config/slices/[slice_name].rb`, which you can then use for customising per-slice config and behavior, e.g.
17
+
18
+ ```ruby
19
+ # config/slices/main.rb:
20
+
21
+ module Main
22
+ class Slice < Hanami::Slice
23
+ # slice config here
24
+ end
25
+ end
26
+ ```
27
+ - [Tim Riley] Application-level `config.slice(slice_name, &block)` setting has been removed in favour of slice configuration within concrete slice class definitions
28
+ - [Tim Riley] You can configure your slice imports inside your slice classes, e.g.
29
+
30
+ ```ruby
31
+ # config/slices/main.rb:
32
+
33
+ module Main
34
+ class Slice < Hanami::Slice
35
+ # Import all exported components from "search" slice
36
+ import from: :search
37
+ end
38
+ end
39
+ ```
40
+ - [Tim Riley] You can configure your slice exports inside your slice classes, e.g.
41
+
42
+ ```ruby
43
+ # config/slices/search.rb:
44
+
45
+ module Search
46
+ class Slice < Hanami::Slice
47
+ # Export the "index_entity" component only
48
+ export ["index_entity"]
49
+ end
50
+ end
51
+ ```
52
+ - [Tim Riley] For advanced cases, you can configure your slice's container via a `prepare_container` block:
53
+
54
+ ```ruby
55
+ # config/slices/search.rb:
56
+
57
+ module Search
58
+ class Slice < Hanami::Slice
59
+ prepare_container do |container|
60
+ # `container` object is available here, with
61
+ # slice-specific configuration already applied
62
+ end
63
+ end
64
+ end
65
+ ```
66
+ - [Tim Riley] `Hanami::Application.shutdown` will now also shutdown all registered slices
67
+
68
+ ## v2.0.0.alpha6 - 2022-02-10
69
+ ### Added
70
+ - [Luca Guidi] Official support for Ruby: MRI 3.1
71
+ - [Tim Riley] Introduce partial Slice imports and exports. It allows to selectively export a functionality from a slice and import into another.
72
+
73
+ Import from `search` slice, uses `search` as the imported key namespace:
74
+
75
+ ```ruby
76
+ # config/application.rb
77
+
78
+ module MyApp
79
+ class Application < Hanami::Application
80
+ config.slice(:admin) do
81
+ import(from: :search)
82
+ end
83
+ end
84
+ end
85
+ ```
86
+
87
+ Import from `search` slice with custom namespace:
88
+
89
+ ```ruby
90
+ # config/application.rb
91
+
92
+ module MyApp
93
+ class Application < Hanami::Application
94
+ config.slice(:admin) do
95
+ import(from: :search, as: :search_engine)
96
+ end
97
+ end
98
+ end
99
+ ```
100
+
101
+ Import specific keys from `search` slice
102
+
103
+ ```ruby
104
+ # config/application.rb
105
+
106
+ module MyApp
107
+ class Application < Hanami::Application
108
+ config.slice(:admin) do
109
+ import(keys: ["run_query"], from: :search)
110
+ end
111
+ end
112
+ end
113
+ ```
114
+
115
+ Export only specific keys from `search` slice, and import them in `admin`
116
+
117
+ ```ruby
118
+ # config/application.rb
119
+
120
+ module MyApp
121
+ class Application < Hanami::Application
122
+ config.slice(:admin) do
123
+ import(from: :search)
124
+ end
125
+
126
+ config.slice(:search) do
127
+ container.config.exports = %w[run_query index_item]
128
+ end
129
+ end
130
+ end
131
+ ```
132
+
133
+ ### Fixed
134
+ - [Luca Guidi] Ensure request logger to respect logger formatter option.
135
+
136
+ ### Changed
137
+ - [Luca Guidi] Drop support for Ruby: MRI 2.6 and 2.7.
138
+ - [Tim Riley] `Hanami.init` => `Hanami.prepare` and `hanami/init` => `hanami/prepare`
139
+ - [Tim Riley] `Hanami.register_bootable` => `Hanami.register_provider`
140
+ - [Tim Riley] `Hanami.start_bootable` => `Hanami.start`
141
+ - [Tim Riley] `Hanami::Slice#init` => `Hanami::Slice#prepare`
142
+ - [Tim Riley] `Hanami::Slice#register_bootable` => `Hanami::Slice#register_provider`
143
+ - [Tim Riley] `Hanami::Slice#start_bootable` => `Hanami::Slice#start`
144
+
4
145
  ## v2.0.0.alpha5 - 2022-01-12
5
146
  ### Changed
6
147
  - [Luca Guidi] Sensible default configuration for application logger, with per-environment defaults:
data/README.md CHANGED
@@ -36,7 +36,7 @@ These components are designed to be used independently or together in a Hanami a
36
36
 
37
37
  ## Installation
38
38
 
39
- __Hanami__ supports Ruby (MRI) 2.6+
39
+ __Hanami__ supports Ruby (MRI) 3.0+
40
40
 
41
41
  ```shell
42
42
  gem install hanami
@@ -136,8 +136,4 @@ __Hanami__ uses [Semantic Versioning 2.0.0](http://semver.org)
136
136
 
137
137
  ## Copyright
138
138
 
139
- Released under MIT License.
140
-
141
- This project was formerly known as Lotus (`lotusrb`).
142
-
143
- Copyright © 2014-2021 Luca Guidi.
139
+ Copyright © 2014-2022 Hanami Team – Released under MIT License.
data/hanami.gemspec CHANGED
@@ -4,7 +4,7 @@ lib = File.expand_path("../lib", __FILE__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
  require "hanami/version"
6
6
 
7
- Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
7
+ Gem::Specification.new do |spec|
8
8
  spec.name = "hanami"
9
9
  spec.version = Hanami::VERSION
10
10
  spec.authors = ["Luca Guidi"]
@@ -14,10 +14,11 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
14
14
  spec.homepage = "http://hanamirb.org"
15
15
  spec.license = "MIT"
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
+ 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") # rubocop:disable Layout/LineLength
18
18
  spec.test_files = spec.files.grep(%r{^(test)/})
19
19
  spec.require_paths = ["lib"]
20
- spec.required_ruby_version = ">= 2.6.0"
20
+ spec.metadata["rubygems_mfa_required"] = "true"
21
+ spec.required_ruby_version = ">= 3.0"
21
22
 
22
23
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
23
24
 
@@ -26,7 +27,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
26
27
  spec.add_dependency "dry-core", "~> 0.4"
27
28
  spec.add_dependency "dry-inflector", "~> 0.2", ">= 0.2.1"
28
29
  spec.add_dependency "dry-monitor"
29
- spec.add_dependency "dry-system", "~> 0.22", ">= 0.22.0"
30
+ spec.add_dependency "dry-system", "~> 0.23", ">= 0.23.0"
30
31
  spec.add_dependency "hanami-cli", "~> 2.0.alpha"
31
32
  spec.add_dependency "hanami-utils", "~> 2.0.alpha"
32
33
  spec.add_dependency "zeitwerk", "~> 2.4"
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Hanami.application.register_bootable :inflector do
3
+ Hanami.application.register_provider :inflector do
4
4
  start do
5
5
  register :inflector, Hanami.application.inflector
6
6
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Hanami.application.register_bootable :logger do
3
+ Hanami.application.register_provider :logger do
4
4
  start do
5
5
  register :logger, Hanami.application.configuration.logger_instance
6
6
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ Hanami.application.register_provider :rack_logger do
4
+ start do
5
+ require "hanami/web/rack_logger"
6
+
7
+ target.start :logger
8
+ target.start :rack_monitor
9
+
10
+ rack_logger = Hanami::Web::RackLogger.new(target[:logger])
11
+ rack_logger.attach target[:rack_monitor]
12
+
13
+ register :rack_logger, rack_logger
14
+ end
15
+ end
@@ -1,11 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Hanami.application.register_bootable :rack_monitor do |container|
3
+ Hanami.application.register_provider :rack_monitor do
4
4
  start do
5
5
  require "dry/monitor"
6
6
  require "dry/monitor/rack/middleware"
7
7
 
8
- middleware = Dry::Monitor::Rack::Middleware.new(container[:notifications])
8
+ middleware = Dry::Monitor::Rack::Middleware.new(target[:notifications])
9
9
 
10
10
  register :rack_monitor, middleware
11
11
  end
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Hanami.application.register_bootable :routes_helper do
3
+ Hanami.application.register_provider :routes_helper do
4
4
  start do
5
5
  require "hanami/application/routes_helper"
6
6
 
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- Hanami.application.register_bootable :settings do
3
+ Hanami.application.register_provider :settings do
4
4
  start do
5
5
  register :settings, Hanami.application.settings
6
6
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  # require "hanami/application/router"
4
4
 
5
- # Hanami.application.register_bootable :router do
5
+ # Hanami.application.register_provider :router do
6
6
  # start do
7
7
  # configuration = Hanami.application.configuration
8
8
 
@@ -0,0 +1,106 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../constants"
4
+ require_relative "../slice"
5
+
6
+ module Hanami
7
+ class Application
8
+ # @api private
9
+ class SliceRegistrar
10
+ attr_reader :application, :slices
11
+ private :application, :slices
12
+
13
+ def initialize(application)
14
+ @application = application
15
+ @slices = {}
16
+ end
17
+
18
+ def register(name, slice_class = nil, &block)
19
+ if slices.key?(name.to_sym)
20
+ raise SliceLoadError, "Slice '#{name}' is already registered"
21
+ end
22
+
23
+ # TODO: raise error unless name meets format (i.e. single level depth only)
24
+
25
+ slices[name.to_sym] = slice_class || build_slice(name, &block)
26
+ end
27
+
28
+ def [](name)
29
+ slices.fetch(name) do
30
+ raise SliceLoadError, "Slice '#{name}' not found"
31
+ end
32
+ end
33
+
34
+ def freeze
35
+ slices.freeze
36
+ super
37
+ end
38
+
39
+ def load_slices
40
+ slice_configs = Dir[root.join(CONFIG_DIR, "slices", "*#{RB_EXT}")]
41
+ .map { |file| File.basename(file, RB_EXT) }
42
+
43
+ slice_dirs = Dir[File.join(root, SLICES_DIR, "*")]
44
+ .select { |path| File.directory?(path) }
45
+ .map { |path| File.basename(path) }
46
+
47
+ (slice_dirs + slice_configs).uniq.sort.each do |slice_name|
48
+ load_slice(slice_name)
49
+ end
50
+
51
+ self
52
+ end
53
+
54
+ def each(&block)
55
+ slices.each_value(&block)
56
+ end
57
+
58
+ def to_a
59
+ slices.values
60
+ end
61
+
62
+ private
63
+
64
+ # Attempts to load a slice class defined in `config/slices/[slice_name].rb`, then
65
+ # registers the slice with the matching class, if found.
66
+ def load_slice(slice_name)
67
+ slice_const_name = inflector.camelize(slice_name)
68
+ slice_require_path = root.join("config", "slices", slice_name).to_s
69
+
70
+ begin
71
+ require(slice_require_path)
72
+ rescue LoadError => e
73
+ raise e unless e.path == slice_require_path
74
+ end
75
+
76
+ slice_class =
77
+ begin
78
+ inflector.constantize("#{slice_const_name}::Slice")
79
+ rescue NameError # rubocop:disable Lint/SuppressedException
80
+ end
81
+
82
+ register(slice_name, slice_class)
83
+ end
84
+
85
+ def build_slice(slice_name, &block)
86
+ slice_module =
87
+ begin
88
+ slice_module_name = inflector.camelize(slice_name.to_s)
89
+ inflector.constantize(slice_module_name)
90
+ rescue NameError
91
+ Object.const_set(inflector.camelize(slice_module_name), Module.new)
92
+ end
93
+
94
+ slice_module.const_set(:Slice, Class.new(Hanami::Slice, &block))
95
+ end
96
+
97
+ def root
98
+ application.root
99
+ end
100
+
101
+ def inflector
102
+ application.inflector
103
+ end
104
+ end
105
+ end
106
+ end