hanami-router 0.7.0 → 0.8.0

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: 393f316c6e21157b2ac3d3d7a9544c9311e55c41
4
- data.tar.gz: 887ed0b0c22b13bf105a621b2cfb9f8ce7542ea7
3
+ metadata.gz: c416e1d26debdd38c991e1d26e4fa0f00db09fc6
4
+ data.tar.gz: ed52730ca7766727ec933d5b3c082b90fd3e1c26
5
5
  SHA512:
6
- metadata.gz: 4fc20e2fe87c4fd3f2a7c088d26836dca184f7dfa4918930793442f7fabecd99de3eaec56c16d2e0fe85cca6f5b90b21607efaa297b27868dad5a0701e0de649
7
- data.tar.gz: 722378463a90b9ea3ebcd5151a630a776655ce37d1025389b5dda41f4bd76e7345506a44188ad10c6ec8d2af8f35a741419665afc0704ce782d8596db3d0d5ac
6
+ metadata.gz: b9b254c39fb3e4d74e6acf2d3ed3fa12da839f2365c67743d7b5ba31c24892f79cf66a2913669064df3b419dd2c5df783c9b2341fd5d8283c6e7855dab3e1d82
7
+ data.tar.gz: 160dba7b24852b5540b1fbbad66567e3ea2ba16ae2a67d91e534a3778ffea16dcfb8c8f9f483fba863fb0c17355dc4883fe347befbdf8d6aaecd6e40929461f8
data/CHANGELOG.md CHANGED
@@ -1,6 +1,17 @@
1
1
  # Hanami::Router
2
2
  Rack compatible HTTP router for Ruby
3
3
 
4
+ ## v0.8.0 - 2016-11-15
5
+ ### Added
6
+ - [Kyle Chong] Referenced params from body parses in Rack env via `router.parsed_body`
7
+
8
+ ### Fixed
9
+ - [Luca Guidi & Lucas Hosseini] Ensure params from routes take precedence over params from body parsing
10
+ - [Luca Guidi] Ensure inspector to respect path prefix of mouted apps
11
+
12
+ ### Changed
13
+ - [Luca Guidi] Official support for Ruby: MRI 2.3+ and JRuby 9.1.5.0+
14
+
4
15
  ## v0.7.0 - 2016-07-22
5
16
  ### Added
6
17
  - [Sean Collins] Introduced `Hanami::Router#root`. Example: `root to: 'home#index'`, equivalent to `get '/', to: 'home#index', as: :root`.
data/README.md CHANGED
@@ -22,7 +22,7 @@ Rack compatible, lightweight and fast HTTP Router for Ruby and [Hanami](http://h
22
22
 
23
23
  ## Rubies
24
24
 
25
- __Hanami::Router__ supports Ruby (MRI) 2.2+, JRuby 9k+
25
+ __Hanami::Router__ supports Ruby (MRI) 2.3+, JRuby 9.1.5.0+
26
26
 
27
27
 
28
28
  ## Installation
@@ -17,11 +17,11 @@ Gem::Specification.new do |spec|
17
17
  spec.executables = []
18
18
  spec.test_files = spec.files.grep(%r{^(test)/})
19
19
  spec.require_paths = ['lib']
20
- spec.required_ruby_version = '>= 2.2.0'
20
+ spec.required_ruby_version = '>= 2.3.0'
21
21
 
22
22
  spec.add_dependency 'rack', '~> 1.6'
23
23
  spec.add_dependency 'http_router', '~> 0.11'
24
- spec.add_dependency 'hanami-utils', '~> 0.8'
24
+ spec.add_dependency 'hanami-utils', '~> 0.9'
25
25
 
26
26
  spec.add_development_dependency 'bundler', '~> 1.5'
27
27
  spec.add_development_dependency 'minitest', '~> 5'
@@ -1,6 +1,6 @@
1
1
  module Hanami
2
2
  class Router
3
3
  # @since 0.1.0
4
- VERSION = '0.7.0'.freeze
4
+ VERSION = '0.8.0'.freeze
5
5
  end
6
6
  end
data/lib/hanami/router.rb CHANGED
@@ -499,6 +499,44 @@ module Hanami
499
499
  @router.trace(path, options, &blk)
500
500
  end
501
501
 
502
+ # Defines a route that accepts a LINK request for the given path.
503
+ #
504
+ # @param path [String] the relative URL to be matched
505
+ #
506
+ # @param options [Hash] the options to customize the route
507
+ # @option options [String,Proc,Class,Object#call] :to the endpoint
508
+ #
509
+ # @param blk [Proc] the anonymous proc to be used as endpoint for the route
510
+ #
511
+ # @return [Hanami::Routing::Route] this may vary according to the :route
512
+ # option passed to the constructor
513
+ #
514
+ # @see Hanami::Router#get
515
+ #
516
+ # @since 0.8.0
517
+ def link(path, options = {}, &blk)
518
+ @router.link(path, options, &blk)
519
+ end
520
+
521
+ # Defines a route that accepts an UNLINK request for the given path.
522
+ #
523
+ # @param path [String] the relative URL to be matched
524
+ #
525
+ # @param options [Hash] the options to customize the route
526
+ # @option options [String,Proc,Class,Object#call] :to the endpoint
527
+ #
528
+ # @param blk [Proc] the anonymous proc to be used as endpoint for the route
529
+ #
530
+ # @return [Hanami::Routing::Route] this may vary according to the :route
531
+ # option passed to the constructor
532
+ #
533
+ # @see Hanami::Router#get
534
+ #
535
+ # @since 0.8.0
536
+ def unlink(path, options = {}, &blk)
537
+ @router.unlink(path, options, &blk)
538
+ end
539
+
502
540
  # Defines a root route (a GET route for '/')
503
541
  #
504
542
  # @param options [Hash] the options to customize the route
@@ -1165,7 +1203,7 @@ module Hanami
1165
1203
  # logout GET, HEAD /logout Sessions::Destroy
1166
1204
  def inspector
1167
1205
  require 'hanami/routing/routes_inspector'
1168
- Routing::RoutesInspector.new(@router.routes)
1206
+ Routing::RoutesInspector.new(@router.routes, @router.prefix)
1169
1207
  end
1170
1208
 
1171
1209
  protected
@@ -1,6 +1,5 @@
1
1
  require 'uri'
2
2
  require 'http_router'
3
- require 'hanami/utils/io'
4
3
  require 'hanami/routing/endpoint_resolver'
5
4
  require 'hanami/routing/route'
6
5
  require 'hanami/routing/parsers'
@@ -8,10 +7,6 @@ require 'hanami/routing/force_ssl'
8
7
  require 'hanami/routing/error'
9
8
  require 'hanami/utils/path_prefix'
10
9
 
11
- Hanami::Utils::IO.silence_warnings do
12
- HttpRouter::Route::VALID_HTTP_VERBS = %w{GET POST PUT PATCH DELETE HEAD OPTIONS TRACE}
13
- end
14
-
15
10
  module Hanami
16
11
  module Routing
17
12
  # Invalid route
@@ -60,6 +55,10 @@ module Hanami
60
55
  # @api private
61
56
  attr_reader :namespace
62
57
 
58
+ # @since 0.8.0
59
+ # @api private
60
+ attr_reader :prefix
61
+
63
62
  # Initialize the router.
64
63
  #
65
64
  # @see Hanami::Router#initialize
@@ -1,4 +1,5 @@
1
1
  require 'hanami/routing/parsing/parser'
2
+ require 'hanami/utils/hash'
2
3
 
3
4
  module Hanami
4
5
  module Routing
@@ -8,6 +9,7 @@ module Hanami
8
9
 
9
10
  RACK_INPUT = 'rack.input'.freeze
10
11
  ROUTER_PARAMS = 'router.params'.freeze
12
+ ROUTER_PARSED_BODY = 'router.parsed_body'.freeze
11
13
  FALLBACK_KEY = '_'.freeze
12
14
 
13
15
  def initialize(parsers)
@@ -47,25 +49,25 @@ module Hanami
47
49
  env[RACK_INPUT].rewind # somebody might try to read this stream
48
50
 
49
51
  env[ROUTER_PARAMS] ||= {} # prepare params
50
- env[ROUTER_PARAMS].merge!(
51
- _parse(env, body)
52
- )
52
+ env[ROUTER_PARSED_BODY] = _parse(env, body)
53
+ env[ROUTER_PARAMS] = _symbolize(env[ROUTER_PARSED_BODY]).merge(env[ROUTER_PARAMS])
53
54
 
54
55
  env
55
56
  end
56
57
  end
57
58
 
59
+ def _symbolize(body)
60
+ if body.is_a?(Hash)
61
+ Utils::Hash.new(body).deep_dup.symbolize!.to_h
62
+ else
63
+ { FALLBACK_KEY => body }
64
+ end
65
+ end
66
+
58
67
  def _parse(env, body)
59
- result = @parsers[
68
+ @parsers[
60
69
  media_type(env)
61
70
  ].parse(body)
62
-
63
- case result
64
- when Hash
65
- result
66
- else
67
- {FALLBACK_KEY => result}
68
- end
69
71
  end
70
72
 
71
73
  def media_type(env)
@@ -47,8 +47,9 @@ module Hanami
47
47
  #
48
48
  # @since 0.2.0
49
49
  # @api private
50
- def initialize(routes)
50
+ def initialize(routes, prefix)
51
51
  @routes = routes
52
+ @prefix = prefix
52
53
  end
53
54
 
54
55
  # Return a formatted string that describes all the routes
@@ -133,7 +134,7 @@ module Hanami
133
134
  # | GET, HEAD | | /admin/home | Home::Index |
134
135
  # | GET, HEAD | | /api/posts | Posts::Index |
135
136
  # | GET, HEAD | | /api/second_mount/comments | Comments::Index |
136
- def to_s(formatter = FORMATTER, base_path = nil)
137
+ def to_s(formatter = FORMATTER, base_path = prefix)
137
138
  base_path = Utils::PathPrefix.new(base_path)
138
139
 
139
140
  inspect_routes(formatter, base_path)
@@ -171,6 +172,10 @@ module Hanami
171
172
 
172
173
  private
173
174
 
175
+ # @since 0.8.0
176
+ # @api private
177
+ attr_reader :prefix
178
+
174
179
  # Returns a string representation of the given route
175
180
  #
176
181
  # @param formatter [String] the template for the output
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hanami-router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-07-22 00:00:00.000000000 Z
13
+ date: 2016-11-15 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack
@@ -46,14 +46,14 @@ dependencies:
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '0.8'
49
+ version: '0.9'
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '0.8'
56
+ version: '0.9'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: bundler
59
59
  requirement: !ruby/object:Gem::Requirement
@@ -156,7 +156,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
156
  requirements:
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 2.2.0
159
+ version: 2.3.0
160
160
  required_rubygems_version: !ruby/object:Gem::Requirement
161
161
  requirements:
162
162
  - - ">="