hanami-controller 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/hanami-controller.gemspec +2 -1
- data/lib/hanami/action/mime.rb +52 -29
- data/lib/hanami/action/params.rb +1 -1
- data/lib/hanami/controller/version.rb +1 -1
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 515508087dbc6e4c68bcb8deb1dea2afaef25717
|
4
|
+
data.tar.gz: cc6fdaa0c425ca9391c8951e60637d1c15cd1982
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0ce65d579990a9e4295a1f5906d927f80911358331e49545188860b72f783f26841628c5466b57c74d1d028f9fac0ec9b905b91ef67abc8df812d36b21277773
|
7
|
+
data.tar.gz: 7c3cbcfd5066a33489c20c391124b806b5e3275c851d2268cc495451c22d76bf673291b8fe372b18ef1928c1842e50e16465452ba38d5d8046e6e76e55673480
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Hanami::Controller
|
2
2
|
Complete, fast and testable actions for Rack
|
3
3
|
|
4
|
+
## v1.0.1 - 2017-07-10
|
5
|
+
### Fixed
|
6
|
+
- [Marcello Rocha] Ensure validation params to be symbolized in all the environments
|
7
|
+
- [Marcello Rocha] Fix regression (`1.0.0`) about MIME type priority, during the evaluation of a weighted `Accept` HTTP header
|
8
|
+
|
4
9
|
## v1.0.0 - 2017-04-06
|
5
10
|
|
6
11
|
## v1.0.0.rc1 - 2017-03-31
|
data/hanami-controller.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |spec|
|
|
15
15
|
|
16
16
|
spec.files = `git ls-files -- lib/* CHANGELOG.md LICENSE.md README.md hanami-controller.gemspec`.split($/)
|
17
17
|
spec.executables = []
|
18
|
-
spec.test_files = spec.files.grep(%r{^(
|
18
|
+
spec.test_files = spec.files.grep(%r{^(spec)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
spec.required_ruby_version = '>= 2.3.0'
|
21
21
|
|
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.6'
|
26
26
|
spec.add_development_dependency 'rack-test', '~> 0.6'
|
27
27
|
spec.add_development_dependency 'rake', '~> 11'
|
28
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
28
29
|
end
|
data/lib/hanami/action/mime.rb
CHANGED
@@ -265,13 +265,8 @@ module Hanami
|
|
265
265
|
# end
|
266
266
|
def content_type
|
267
267
|
return @content_type unless @content_type.nil?
|
268
|
-
|
269
|
-
|
270
|
-
type = content_type_from_accept_header
|
271
|
-
return type if type
|
272
|
-
end
|
273
|
-
|
274
|
-
default_response_type || default_content_type || DEFAULT_CONTENT_TYPE
|
268
|
+
@content_type = content_type_from_accept_header if accept_header?
|
269
|
+
@content_type || default_response_type || default_content_type || DEFAULT_CONTENT_TYPE
|
275
270
|
end
|
276
271
|
|
277
272
|
# Action charset setter, receives new charset value
|
@@ -565,33 +560,61 @@ module Hanami
|
|
565
560
|
# @see https://github.com/rack/rack/pull/659
|
566
561
|
# @see https://github.com/hanami/controller/issues/59
|
567
562
|
# @see https://github.com/hanami/controller/issues/104
|
563
|
+
# @see https://github.com/hanami/controller/issues/275
|
568
564
|
def best_q_match(q_value_header, available_mimes)
|
569
|
-
|
570
|
-
|
571
|
-
if req_mime == DEFAULT_ACCEPT
|
572
|
-
# See https://github.com/hanami/controller/issues/167
|
573
|
-
match = default_content_type
|
574
|
-
else
|
575
|
-
match = available_mimes.find { |am| ::Rack::Mime.match?(am, req_mime) }
|
576
|
-
end
|
565
|
+
::Rack::Utils.q_values(q_value_header).each_with_index.map do |(req_mime, quality), index|
|
566
|
+
match = available_mimes.find { |am| ::Rack::Mime.match?(am, req_mime) }
|
577
567
|
next unless match
|
578
|
-
|
579
|
-
end.compact
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
568
|
+
RequestMimeWeight.new(req_mime, quality, index, match)
|
569
|
+
end.compact.max&.format
|
570
|
+
end
|
571
|
+
|
572
|
+
# @since 1.0.1
|
573
|
+
# @api private
|
574
|
+
class RequestMimeWeight
|
575
|
+
include Comparable
|
576
|
+
|
577
|
+
# @since 1.0.1
|
578
|
+
# @api private
|
579
|
+
attr_reader :quality
|
580
|
+
|
581
|
+
# @since 1.0.1
|
582
|
+
# @api private
|
583
|
+
attr_reader :index
|
584
|
+
|
585
|
+
# @since 1.0.1
|
586
|
+
# @api private
|
587
|
+
attr_reader :mime
|
588
|
+
|
589
|
+
# @since 1.0.1
|
590
|
+
# @api private
|
591
|
+
attr_reader :format
|
592
|
+
|
593
|
+
# @since 1.0.1
|
594
|
+
# @api private
|
595
|
+
attr_reader :priority
|
596
|
+
|
597
|
+
# @since 1.0.1
|
598
|
+
# @api private
|
599
|
+
def initialize(mime, quality, index, format = mime)
|
600
|
+
@quality, @index, @format = quality, index, format
|
601
|
+
calculate_priority(mime)
|
588
602
|
end
|
589
603
|
|
590
|
-
|
591
|
-
|
592
|
-
|
604
|
+
# @since 1.0.1
|
605
|
+
# @api private
|
606
|
+
def <=>(other)
|
607
|
+
return priority <=> other.priority unless priority == other.priority
|
608
|
+
other.index <=> index
|
609
|
+
end
|
610
|
+
|
611
|
+
private
|
593
612
|
|
594
|
-
|
613
|
+
# @since 1.0.1
|
614
|
+
# @api private
|
615
|
+
def calculate_priority(mime)
|
616
|
+
@priority ||= (mime.split('/'.freeze, 2).count('*'.freeze) * -10) + quality
|
617
|
+
end
|
595
618
|
end
|
596
619
|
end
|
597
620
|
end
|
data/lib/hanami/action/params.rb
CHANGED
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.0.
|
4
|
+
version: 1.0.1
|
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
|
+
date: 2017-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '11'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.5'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.5'
|
83
97
|
description: Complete, fast and testable actions for Rack
|
84
98
|
email:
|
85
99
|
- me@lucaguidi.com
|