hanami-controller 1.1.1 → 1.2.0.beta1

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: dec60bc59285348cfcf6fc743dbc586d8bd7356bfb02197db37bc18fe0131fcd
4
- data.tar.gz: c8b851ca2730d18b886dcb4300fdcd28c31c12cf03df5505c995bd4a3819ef28
3
+ metadata.gz: 5044ea5ed0faca05bc15bf6b9deeb1ba48dd973d2d54ce26adc4279f2876a3b0
4
+ data.tar.gz: f451bf0b3f4065aa31b03085f9869058615c8a9bc81314071d17a052efff3f99
5
5
  SHA512:
6
- metadata.gz: a0bdc218188b3f71d5bd22bd11e81fae44089dad09191ed31ea5a1da742e4ea007df521e899469bbe01e3fd8d28d9652ec032589e83e817733a53144860a8582
7
- data.tar.gz: f0f04ea096539c67c1413dc1a527b68aa258a155389324601c9cbf419c1423f0eb6fcf8a23cce67f49cf4d1109a98dd3f068f6a88dcff5b8d337fd2dba66fd91
6
+ metadata.gz: e81ba4a549949b0fd85f3143d96620bc319028ef73b6130a1f6f93df31ec32b3b2db838cdd56b62346c61d290c75e169aee41ecfe521048e9072fcc170941cf3
7
+ data.tar.gz: 33b3a4861eac4269633b1fe7343ffc3c8c011dbb9cde772f13cdc4fb72ab34a781231d903accfaa15c8755950b3e18f16123955cc1db43fb6028d071abd22456
data/CHANGELOG.md CHANGED
@@ -1,6 +1,14 @@
1
1
  # Hanami::Controller
2
2
  Complete, fast and testable actions for Rack
3
3
 
4
+ ## v1.2.0.beta1 - 2018-02-28
5
+ ### Added
6
+ - [Luca Guidi] Official support for Ruby: MRI 2.5
7
+ - [Sergey Fedorov] Introduce `Hanami::Action.content_type` to accept/reject requests according to their `Content-Type` header.
8
+
9
+ ### Fixed
10
+ - [wheresmyjetpack] Raise meaningful exception when trying to access `session` or `flash` and `Hanami::Action::Session` wasn't included.
11
+
4
12
  ## v1.1.1 - 2017-11-22
5
13
  ### Fixed
6
14
  - [Luca Guidi] Ensure `Hanami::Action#send_file` and `#unsafe_send_file` to run `after` action callbacks
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
  spec.required_ruby_version = '>= 2.3.0'
21
21
 
22
22
  spec.add_dependency 'rack', '~> 2.0'
23
- spec.add_dependency 'hanami-utils', '~> 1.1'
23
+ spec.add_dependency 'hanami-utils', '1.2.0.beta1'
24
24
 
25
25
  spec.add_development_dependency 'bundler', '~> 1.6'
26
26
  spec.add_development_dependency 'rack-test', '~> 0.6'
data/lib/hanami/action.rb CHANGED
@@ -66,6 +66,28 @@ module Hanami
66
66
 
67
67
  private
68
68
 
69
+ # Raise error when `Hanami::Action::Session` isn't included.
70
+ #
71
+ # To use `session`, include `Hanami::Action::Session`.
72
+ #
73
+ # @raise [Hanami::Controller::MissingSessionError]
74
+ #
75
+ # @since 1.2.0
76
+ def session
77
+ raise Hanami::Controller::MissingSessionError.new(:session)
78
+ end
79
+
80
+ # Raise error when `Hanami::Action::Session` isn't included.
81
+ #
82
+ # To use `flash`, include `Hanami::Action::Session`.
83
+ #
84
+ # @raise [Hanami::Controller::MissingSessionError]
85
+ #
86
+ # @since 1.2.0
87
+ def flash
88
+ raise Hanami::Controller::MissingSessionError.new(:flash)
89
+ end
90
+
69
91
  # Finalize the response
70
92
  #
71
93
  # This method is abstract and COULD be implemented by included modules in
@@ -16,6 +16,12 @@ module Hanami
16
16
  # @api private
17
17
  HTTP_ACCEPT = 'HTTP_ACCEPT'.freeze
18
18
 
19
+ # The key that returns content mime type from the Rack env
20
+ #
21
+ # @since 1.2.0
22
+ # @api private
23
+ HTTP_CONTENT_TYPE = 'CONTENT_TYPE'.freeze
24
+
19
25
  # The header key to set the mime type of the response
20
26
  #
21
27
  # @since 0.1.0
@@ -165,6 +171,38 @@ module Hanami
165
171
  end
166
172
  end
167
173
  end
174
+
175
+ # Restrict the payload type to the specified mime type symbols.
176
+ #
177
+ # @param formats[Array<Symbol>] one or more symbols representing mime type(s)
178
+ #
179
+ # @since 1.2.0
180
+ #
181
+ # @example
182
+ # require 'hanami/controller'
183
+ #
184
+ # class Upload
185
+ # include Hanami::Action
186
+ # content_type :json
187
+ #
188
+ # def call(params)
189
+ # # ...
190
+ # end
191
+ # end
192
+ #
193
+ # # When called with "text/html" => 415
194
+ # # When called with "application/json" => 200
195
+ def content_type(*formats)
196
+ mime_types = formats.map { |format| format_to_mime_type(format) }
197
+
198
+ before do
199
+ mime_type = @_env[HTTP_CONTENT_TYPE] || default_content_type || DEFAULT_CONTENT_TYPE
200
+
201
+ if mime_types.none? {|mt| ::Rack::Mime.match?(mime_type, mt) }
202
+ halt 415
203
+ end
204
+ end
205
+ end
168
206
  end
169
207
 
170
208
  # @since 0.7.0
@@ -47,6 +47,22 @@ module Hanami
47
47
  end
48
48
  end
49
49
 
50
+ # Missing session error
51
+ #
52
+ # This error is raised when an action sends either `session` or `flash` to
53
+ # itself and it does not include `Hanami::Action::Session`.
54
+ #
55
+ # @since 1.2.0
56
+ #
57
+ # @see Hanami::Action::Session
58
+ # @see Hanami::Action#session
59
+ # @see Hanami::Action#flash
60
+ class MissingSessionError < Hanami::Controller::Error
61
+ def initialize(session_method)
62
+ super("To use `#{session_method}', add `include Hanami::Action::Session`.")
63
+ end
64
+ end
65
+
50
66
  include Utils::ClassAttribute
51
67
 
52
68
  # Framework configuration
@@ -3,6 +3,6 @@ module Hanami
3
3
  # Defines the version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '1.1.1'.freeze
6
+ VERSION = '1.2.0.beta1'.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: 1.1.1
4
+ version: 1.2.0.beta1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-22 00:00:00.000000000 Z
11
+ date: 2018-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: hanami-utils
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
33
+ version: 1.2.0.beta1
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: '1.1'
40
+ version: 1.2.0.beta1
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -153,12 +153,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
153
153
  version: 2.3.0
154
154
  required_rubygems_version: !ruby/object:Gem::Requirement
155
155
  requirements:
156
- - - ">="
156
+ - - ">"
157
157
  - !ruby/object:Gem::Version
158
- version: '0'
158
+ version: 1.3.1
159
159
  requirements: []
160
160
  rubyforge_project:
161
- rubygems_version: 2.7.1
161
+ rubygems_version: 2.7.5
162
162
  signing_key:
163
163
  specification_version: 4
164
164
  summary: Complete, fast and testable actions for Rack and Hanami