hanami-controller 2.0.0.alpha2 → 2.0.0.alpha3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d159c89cbe6b24762a475776ae1585e76925c8f26501c6334c908893624587e5
4
- data.tar.gz: b5f4b394c5337ae9b46f2482f86f69aaf151dbaee9cd2ac95be15f69a12ce65a
3
+ metadata.gz: 015e9bf69c01ea01cbdd9a27e7bf4d4cb4f8f9a98f01a14d707fd68457096006
4
+ data.tar.gz: 0f2c2e2569453264b41e131451caae329cfbd7d6773d50f610355f5f6fd0b62b
5
5
  SHA512:
6
- metadata.gz: aac599272b21e8ca56b2c519b93a47593dc126d442be727d87b4e8884e1c2da3d349d480399e1ed781560acb9e450e24b1985fbcd7083d65d79fb8573c3db606
7
- data.tar.gz: 75beecc46dce543367e7869887cda80937c2d838a65996f9bd831e56dfade6fa1ccccc03c7c0a0ace5aad833e26db10638e6c51e869b70cb6dc95abd351b7000
6
+ metadata.gz: 7eb2b778608f9dd27cbf777dd00b98e079bc1ec790da5e388113d645babbc9972d10272c083e187dfafa875fe0e2387592f34fc4d48b0ff96be920d1d82c12b8
7
+ data.tar.gz: e1290141bb9128031b0593b1edcf2975fe5f01eadb4661fe0bf18c164f339671bf195b43f8933731cab13180b68a7141a4ce6caa01e1df9aabe3e5afb9e0c9a7
data/CHANGELOG.md CHANGED
@@ -1,6 +1,15 @@
1
1
  # Hanami::Controller
2
2
  Complete, fast and testable actions for Rack
3
3
 
4
+ ## v2.0.0.alpha3 - 2021-11-09
5
+ ### Added
6
+ - [Luca Guidi] Automatically include session behavior in `Hanami::Action` when sessions are enabled via Hanami application config
7
+ - [Sean Collins] Pass exposures from action to view
8
+
9
+ ### Changed
10
+ - [Tim Riley] (Internal) Updated settings to use updated `setting` API in dry-configurable 0.13.0
11
+ - [Sean Collins] Move automatic view rendering from `handle` to `finish`
12
+
4
13
  ## v2.0.0.alpha2 - 2021-05-04
5
14
  ### Added
6
15
  - [Luca Guidi] Official support for Ruby: MRI 3.0
data/README.md CHANGED
@@ -2,11 +2,15 @@
2
2
 
3
3
  Complete, fast and testable actions for Rack and [Hanami](http://hanamirb.org)
4
4
 
5
+ ## Version
6
+
7
+ **This branch contains the code for `hanami-controller` 2.x.**
8
+
5
9
  ## Status
6
10
 
7
11
  [![Gem Version](https://badge.fury.io/rb/hanami-controller.svg)](https://badge.fury.io/rb/hanami-controller)
8
- [![CI](https://github.com/hanami/controller/workflows/ci/badge.svg?branch=unstable)](https://github.com/hanami/controller/actions?query=workflow%3Aci+branch%3Aunstable)
9
- [![Test Coverage](https://codecov.io/gh/hanami/controller/branch/unstable/graph/badge.svg)](https://codecov.io/gh/hanami/controller)
12
+ [![CI](https://github.com/hanami/controller/workflows/ci/badge.svg?branch=main)](https://github.com/hanami/controller/actions?query=workflow%3Aci+branch%3Amain)
13
+ [![Test Coverage](https://codecov.io/gh/hanami/controller/branch/main/graph/badge.svg)](https://codecov.io/gh/hanami/controller)
10
14
  [![Depfu](https://badges.depfu.com/badges/7cd17419fba78b726be1353118fb01de/overview.svg)](https://depfu.com/github/hanami/controller?project=Bundler)
11
15
  [![Inline Docs](http://inch-ci.org/github/hanami/controller.svg)](http://inch-ci.org/github/hanami/controller)
12
16
 
@@ -22,7 +26,7 @@ Complete, fast and testable actions for Rack and [Hanami](http://hanamirb.org)
22
26
 
23
27
  ## Rubies
24
28
 
25
- __Hanami::Controller__ supports Ruby (MRI) 2.5+
29
+ __Hanami::Controller__ supports Ruby (MRI) 2.6+
26
30
 
27
31
  ## Installation
28
32
 
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_dependency 'rack', '~> 2.0'
23
23
  spec.add_dependency 'hanami-utils', '~> 2.0.alpha'
24
- spec.add_dependency 'dry-configurable', '~> 0.12'
24
+ spec.add_dependency 'dry-configurable', '~> 0.13', '>= 0.13.0'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '>= 1.6', '< 3'
27
27
  spec.add_development_dependency 'rack-test', '~> 1.0'
@@ -68,6 +68,11 @@ module Hanami
68
68
  end
69
69
 
70
70
  def extend_behavior(action_class)
71
+ if application.config.actions.sessions.enabled?
72
+ require "hanami/action/session"
73
+ action_class.include Hanami::Action::Session
74
+ end
75
+
71
76
  if application.config.actions.csrf_protection
72
77
  require "hanami/action/csrf_protection"
73
78
  action_class.include Hanami::Action::CSRFProtection
@@ -83,16 +88,6 @@ module Hanami
83
88
  attr_reader :view
84
89
  attr_reader :view_context
85
90
 
86
- protected
87
-
88
- def handle(request, response)
89
- if view
90
- response.render view, **request.params
91
- end
92
- end
93
-
94
- private
95
-
96
91
  def build_response(**options)
97
92
  options = options.merge(view_options: method(:view_options))
98
93
  super(**options)
@@ -105,6 +100,12 @@ module Hanami
105
100
  def view_context_options(req, res)
106
101
  {request: req, response: res}
107
102
  end
103
+
104
+ # Automatically render the view, if the body hasn't been populated yet
105
+ def finish(req, res, halted)
106
+ res.render(view, **req.params, **res.exposures) if view && res.body.empty?
107
+ super
108
+ end
108
109
  end
109
110
  end
110
111
  end
@@ -10,14 +10,14 @@ module Hanami
10
10
  class ApplicationConfiguration
11
11
  include Dry::Configurable
12
12
 
13
- setting(:cookies, {}) { |options| Cookies.new(options) }
14
- setting(:sessions) { |storage, *options| Sessions.new(storage, *options) }
13
+ setting :cookies, default: {}, constructor: -> options { Cookies.new(options) }
14
+ setting :sessions, constructor: proc { |storage, *options| Sessions.new(storage, *options) }
15
15
  setting :csrf_protection
16
16
 
17
- setting :name_inference_base, "actions"
18
- setting :view_context_identifier, "view.context"
19
- setting :view_name_inferrer, ViewNameInferrer
20
- setting :view_name_inference_base, "views"
17
+ setting :name_inference_base, default: "actions"
18
+ setting :view_context_identifier, default: "view.context"
19
+ setting :view_name_inferrer, default: ViewNameInferrer
20
+ setting :view_name_inference_base, default: "views"
21
21
 
22
22
  def initialize(*)
23
23
  super
@@ -58,7 +58,7 @@ module Hanami
58
58
  # @see handled_exceptions=
59
59
  #
60
60
  # @since 0.2.0
61
- setting :handled_exceptions, {}
61
+ setting :handled_exceptions, default: {}
62
62
 
63
63
  # Specifies how to handle exceptions with an HTTP status
64
64
  #
@@ -122,7 +122,7 @@ module Hanami
122
122
  # @see formats=
123
123
  #
124
124
  # @since 0.2.0
125
- setting :formats, DEFAULT_FORMATS.dup
125
+ setting :formats, default: DEFAULT_FORMATS.dup
126
126
 
127
127
  # Registers a MIME type to format mapping
128
128
  #
@@ -211,9 +211,9 @@ module Hanami
211
211
  # @see default_request_format=
212
212
  #
213
213
  # @since 0.5.0
214
- setting :default_request_format do |format|
214
+ setting :default_request_format, constructor: -> format {
215
215
  Utils::Kernel.Symbol(format) unless format.nil?
216
- end
216
+ }
217
217
 
218
218
  # @!method default_response_format=(format)
219
219
  #
@@ -243,9 +243,9 @@ module Hanami
243
243
  # @see default_request_format=
244
244
  #
245
245
  # @since 0.5.0
246
- setting :default_response_format do |format|
246
+ setting :default_response_format, constructor: -> format {
247
247
  Utils::Kernel.Symbol(format) unless format.nil?
248
- end
248
+ }
249
249
 
250
250
  # @!method default_charset=(charset)
251
251
  #
@@ -299,9 +299,7 @@ module Hanami
299
299
  # @since 0.4.0
300
300
  #
301
301
  # @see default_headers=
302
- setting :default_headers, {} do |headers|
303
- headers.compact
304
- end
302
+ setting :default_headers, default: {}, constructor: -> headers { headers.compact }
305
303
 
306
304
  # @!method cookies=(cookie_options)
307
305
  #
@@ -332,11 +330,11 @@ module Hanami
332
330
  # @since 0.4.0
333
331
  #
334
332
  # @see cookies=
335
- setting :cookies, {} do |cookie_options|
333
+ setting :cookies, default: {}, constructor: -> cookie_options {
336
334
  # Call `to_h` here to permit `ApplicationConfiguration::Cookies` object to be
337
335
  # provided when application actions are configured
338
336
  cookie_options.to_h.compact
339
- end
337
+ }
340
338
 
341
339
  # @!method root_directory=(dir)
342
340
  #
@@ -364,11 +362,11 @@ module Hanami
364
362
  # @since 1.0.0
365
363
  #
366
364
  # @api private
367
- setting :root_directory do |dir|
365
+ setting :root_directory, constructor: -> dir {
368
366
  dir ||= Dir.pwd
369
367
 
370
368
  Pathname(dir).realpath
371
- end
369
+ }
372
370
 
373
371
  # Default public directory
374
372
  #
@@ -393,7 +391,7 @@ module Hanami
393
391
  #
394
392
  # @see root_directory
395
393
  # @see public_directory
396
- setting :public_directory, DEFAULT_PUBLIC_DIRECTORY
394
+ setting :public_directory, default: DEFAULT_PUBLIC_DIRECTORY
397
395
 
398
396
  # Returns the configured public directory, appended onto the root directory.
399
397
  #
@@ -553,9 +553,7 @@ module Hanami
553
553
 
554
554
  # Finalize the response
555
555
  #
556
- # This method is abstract and COULD be implemented by included modules in
557
- # order to prepare their data before the response will be returned to the
558
- # webserver.
556
+ # Prepare the data before the response will be returned to the webserver
559
557
  #
560
558
  # @since 0.1.0
561
559
  # @api private
@@ -3,6 +3,6 @@ module Hanami
3
3
  # Defines the version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '2.0.0.alpha2'.freeze
6
+ VERSION = '2.0.0.alpha3'.freeze
7
7
  end
8
8
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-controller
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.alpha2
4
+ version: 2.0.0.alpha3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-04 00:00:00.000000000 Z
11
+ date: 2021-11-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -44,14 +44,20 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.12'
47
+ version: '0.13'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 0.13.0
48
51
  type: :runtime
49
52
  prerelease: false
50
53
  version_requirements: !ruby/object:Gem::Requirement
51
54
  requirements:
52
55
  - - "~>"
53
56
  - !ruby/object:Gem::Version
54
- version: '0.12'
57
+ version: '0.13'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 0.13.0
55
61
  - !ruby/object:Gem::Dependency
56
62
  name: bundler
57
63
  requirement: !ruby/object:Gem::Requirement
@@ -175,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
175
181
  - !ruby/object:Gem::Version
176
182
  version: 1.3.1
177
183
  requirements: []
178
- rubygems_version: 3.2.4
184
+ rubygems_version: 3.2.3
179
185
  signing_key:
180
186
  specification_version: 4
181
187
  summary: Complete, fast and testable actions for Rack and Hanami