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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4597e54bfdd73cec8513d4eaa87e44a3c4b60639
4
- data.tar.gz: 2c0198763912801b11209c23fb92a5e5d61d4364
3
+ metadata.gz: 515508087dbc6e4c68bcb8deb1dea2afaef25717
4
+ data.tar.gz: cc6fdaa0c425ca9391c8951e60637d1c15cd1982
5
5
  SHA512:
6
- metadata.gz: 47cae71662655adfaae7df0d1f15b8e108a3f55c2e4e13e5663b201d1c9541e6ca4495fd30b44d1f79a33186a2b186bdad1e2fc758b87a17089a98d66ff1a870
7
- data.tar.gz: 1d106a2a12d884f6a96e33a12a922909cfc17b4430caec78ca351b3248d8cfa7a293884f5004dc90208db30797b8a2857cc4a82e758b147b1378983e4c330871
6
+ metadata.gz: 0ce65d579990a9e4295a1f5906d927f80911358331e49545188860b72f783f26841628c5466b57c74d1d028f9fac0ec9b905b91ef67abc8df812d36b21277773
7
+ data.tar.gz: 7c3cbcfd5066a33489c20c391124b806b5e3275c851d2268cc495451c22d76bf673291b8fe372b18ef1928c1842e50e16465452ba38d5d8046e6e76e55673480
@@ -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
@@ -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{^(test)/})
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
@@ -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
- if accept_header?
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
- values = ::Rack::Utils.q_values(q_value_header)
570
- values = values.map do |req_mime, quality|
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
- [match, quality]
579
- end.compact
580
-
581
- if Hanami::Utils.jruby?
582
- # See https://github.com/hanami/controller/issues/59
583
- # See https://github.com/hanami/controller/issues/104
584
- values.reverse!
585
- else
586
- # See https://github.com/jruby/jruby/issues/3004
587
- values.sort!
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
- value = values.sort_by do |match, quality|
591
- (match.split('/'.freeze, 2).count('*'.freeze) * -10) + quality
592
- end.last
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
- value.first if value
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
@@ -146,7 +146,7 @@ module Hanami
146
146
 
147
147
  # @api private
148
148
  def _params
149
- @result.output.merge(_router_params)
149
+ _router_params.merge(@result.output)
150
150
  end
151
151
  end
152
152
  end
@@ -3,6 +3,6 @@ module Hanami
3
3
  # Defines the version
4
4
  #
5
5
  # @since 0.1.0
6
- VERSION = '1.0.0'.freeze
6
+ VERSION = '1.0.1'.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.0.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-04-06 00:00:00.000000000 Z
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