hanami-router 1.0.0.beta2 → 1.0.0.beta3

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: f6efe1bf0b84ce27d1aba7571f7d57faee9e63dd
4
- data.tar.gz: 18ae4097f5a5584a5500e3421120fc62b9c6b4d8
3
+ metadata.gz: 4b0aa788bc3fdc570860f8dc2f41635320dd08ea
4
+ data.tar.gz: 77ecacea1b2c3741f6957f528cd327a3a4304a13
5
5
  SHA512:
6
- metadata.gz: 357ad670d55be64cb067e53df95b5b2f30483869c6c9991978e842ed293508b095813a10129dcddc76ddfe3017384b1ebe28930351136c9420337f88aa2743aa
7
- data.tar.gz: 7762a3896731fb24cb81651fe1d5e845f716a51a827ea33bcbb199b4fd9ad4029ad2549a176259d0e0c75b62c7b9fea864a8330f571f24997fe448a720698be8
6
+ metadata.gz: 716ec8875095f22614fac285b27e0548695abc8e8f233abcc01928a8d6a9a096f2634883c5dd8c7ffb0a6758e6573f179c92b0dfe8d4f1b9342281b25ecdea91
7
+ data.tar.gz: 864a3ba5e664f1a18397b6417e805c70449816e5bd0d9101a20e1a111471ac55474fb38da4b687d57c262579311b4fa948cc26a7cc1a8d22b1345004d17f2257
data/CHANGELOG.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # Hanami::Router
2
2
  Rack compatible HTTP router for Ruby
3
3
 
4
+ ## v1.0.0.beta3 - 2017-03-17
5
+
4
6
  ## v1.0.0.beta2 - 2017-03-02
5
7
  ### Fixed
6
8
  - [Valentyn Ostakh] Deep symbolize params from parsed body
data/LICENSE.md CHANGED
@@ -1,4 +1,4 @@
1
- Copyright © 2014-2016 Luca Guidi
1
+ Copyright © 2014-2017 Luca Guidi
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -703,6 +703,6 @@ Thanks to Joshua Hull ([@joshbuddy](https://github.com/joshbuddy)) for his
703
703
 
704
704
  ## Copyright
705
705
 
706
- Copyright © 2014-2016 Luca Guidi – Released under MIT License
706
+ Copyright © 2014-2017 Luca Guidi – Released under MIT License
707
707
 
708
708
  This project was formerly known as Lotus (`lotus-router`).
data/lib/hanami/router.rb CHANGED
@@ -5,6 +5,9 @@ require 'hanami/routing/resource'
5
5
  require 'hanami/routing/resources'
6
6
  require 'hanami/routing/error'
7
7
 
8
+ # Hanami
9
+ #
10
+ # @since 0.1.0
8
11
  module Hanami
9
12
  # Rack compatible, lightweight and fast HTTP Router.
10
13
  #
@@ -83,9 +86,15 @@ module Hanami
83
86
  # @see Hanami::Routing::RecognizedRoute#call
84
87
  # @see Hanami::Routing::RecognizedRoute#routable?
85
88
  class NotRoutableEndpointError < Hanami::Routing::Error
89
+ # @since 0.5.0
90
+ # @api private
86
91
  REQUEST_METHOD = 'REQUEST_METHOD'.freeze
92
+
93
+ # @since 0.5.0
94
+ # @api private
87
95
  PATH_INFO = 'PATH_INFO'.freeze
88
96
 
97
+ # @since 0.5.0
89
98
  def initialize(env)
90
99
  super %(Cannot find routable endpoint for #{ env[REQUEST_METHOD] } "#{ env[PATH_INFO] }")
91
100
  end
@@ -1,6 +1,6 @@
1
1
  module Hanami
2
2
  class Router
3
3
  # @since 0.1.0
4
- VERSION = '1.0.0.beta2'.freeze
4
+ VERSION = '1.0.0.beta3'.freeze
5
5
  end
6
6
  end
@@ -32,6 +32,7 @@ module Hanami
32
32
  # end
33
33
  class Endpoint < SimpleDelegator
34
34
  # @since 0.2.0
35
+ # @api private
35
36
  def inspect
36
37
  case __getobj__
37
38
  when Proc
@@ -84,6 +85,7 @@ module Hanami
84
85
  # Rack interface
85
86
  #
86
87
  # @since 0.1.0
88
+ # @api private
87
89
  def call(env)
88
90
  __getobj__.new.call(env)
89
91
  end
@@ -112,6 +114,7 @@ module Hanami
112
114
  # Initialize the lazy endpoint
113
115
  #
114
116
  # @since 0.1.0
117
+ # @api private
115
118
  def initialize(name, namespace)
116
119
  @name, @namespace = name, namespace
117
120
  end
@@ -121,11 +124,13 @@ module Hanami
121
124
  # @raise [EndpointNotFound] when the endpoint can't be found.
122
125
  #
123
126
  # @since 0.1.0
127
+ # @api private
124
128
  def call(env)
125
129
  obj.call(env)
126
130
  end
127
131
 
128
132
  # @since 0.2.0
133
+ # @api private
129
134
  def inspect
130
135
  # TODO review this implementation once the namespace feature will be
131
136
  # cleaned up.
@@ -58,6 +58,7 @@ module Hanami
58
58
  # @return [Hanami::Routing::EndpointResolver] self
59
59
  #
60
60
  # @since 0.1.0
61
+ # @api private
61
62
  #
62
63
  # @example Specify custom endpoint class
63
64
  # require 'hanami/router'
@@ -117,6 +118,7 @@ module Hanami
117
118
  # passed to #initialize
118
119
  #
119
120
  # @since 0.1.0
121
+ # @api private
120
122
  #
121
123
  # @see #initialize
122
124
  # @see #find
@@ -173,6 +175,7 @@ module Hanami
173
175
  # @option options [String] :namespace an optional namespace
174
176
  #
175
177
  # @since 0.1.0
178
+ # @api private
176
179
  #
177
180
  # @return [Object]
178
181
  def find(options)
@@ -180,12 +183,14 @@ module Hanami
180
183
  end
181
184
 
182
185
  protected
186
+ # @api private
183
187
  def default
184
188
  @endpoint_class.new(
185
189
  ->(env) { DEFAULT_RESPONSE }
186
190
  )
187
191
  end
188
192
 
193
+ # @api private
189
194
  def constantize(string)
190
195
  klass = Utils::Class.load!(string, @namespace)
191
196
  if klass.respond_to?(:call)
@@ -197,11 +202,13 @@ module Hanami
197
202
  LazyEndpoint.new(string, @namespace)
198
203
  end
199
204
 
205
+ # @api private
200
206
  def classify(string)
201
207
  Utils::String.new(string).underscore.classify
202
208
  end
203
209
 
204
210
  private
211
+ # @api private
205
212
  def resolve_callable(callable)
206
213
  if callable.respond_to?(:call)
207
214
  @endpoint_class.new(callable)
@@ -210,6 +217,7 @@ module Hanami
210
217
  end
211
218
  end
212
219
 
220
+ # @api private
213
221
  def resolve_matchable(matchable)
214
222
  if matchable.respond_to?(:match)
215
223
  constantize(
@@ -218,6 +226,7 @@ module Hanami
218
226
  end
219
227
  end
220
228
 
229
+ # @api private
221
230
  def resolve_action(string)
222
231
  if string.match(action_separator)
223
232
  controller, action = string.split(action_separator).map {|token| classify(token) }
@@ -192,6 +192,7 @@ module Hanami
192
192
 
193
193
  private
194
194
 
195
+ # @api private
195
196
  def _rescue_url_recognition
196
197
  yield
197
198
  rescue ::HttpRouter::InvalidRouteException,
@@ -199,10 +200,12 @@ module Hanami
199
200
  raise Routing::InvalidRouteException.new("#{ e.message } - please check given arguments")
200
201
  end
201
202
 
203
+ # @api private
202
204
  def add_with_request_method(path, method, opts = {}, &app)
203
205
  super.generate(@resolver, opts, &app)
204
206
  end
205
207
 
208
+ # @api private
206
209
  def _custom_path(uri_string)
207
210
  uri = URI.parse(uri_string)
208
211
  uri.path = @prefix.join(uri.path)
@@ -3,8 +3,11 @@
3
3
  # This monkey patches http_router to make it Rack 2.0 compatible.
4
4
  # Details see: https://github.com/hanami/router/issues/136
5
5
  #
6
+ # @api private
6
7
  class HttpRouter
8
+ # @api private
7
9
  class Node
10
+ # @api private
8
11
  class Path < Node
9
12
  def to_code
10
13
  path_ivar = inject_root_ivar(self)
@@ -3,25 +3,47 @@ require 'hanami/utils/hash'
3
3
 
4
4
  module Hanami
5
5
  module Routing
6
+ # @since 0.2.0
7
+ # @api private
6
8
  class Parsers
9
+ # @since 0.2.0
10
+ # @api private
7
11
  CONTENT_TYPE = 'CONTENT_TYPE'.freeze
12
+
13
+ # @since 0.2.0
14
+ # @api private
8
15
  MEDIA_TYPE_MATCHER = /\s*[;,]\s*/.freeze
9
16
 
17
+ # @since 0.2.0
18
+ # @api private
10
19
  RACK_INPUT = 'rack.input'.freeze
20
+
21
+ # @since 0.2.0
22
+ # @api private
11
23
  ROUTER_PARAMS = 'router.params'.freeze
24
+
25
+ # @api private
12
26
  ROUTER_PARSED_BODY = 'router.parsed_body'.freeze
27
+
28
+ # @api private
13
29
  FALLBACK_KEY = '_'.freeze
14
30
 
31
+ # @since 0.2.0
32
+ # @api private
15
33
  def initialize(parsers)
16
34
  @parsers = prepare(parsers)
17
35
  _redefine_call
18
36
  end
19
37
 
38
+ # @since 0.2.0
39
+ # @api private
20
40
  def call(env)
21
41
  env
22
42
  end
23
43
 
24
44
  private
45
+ # @since 0.2.0
46
+ # @api private
25
47
  def prepare(args)
26
48
  result = Hash.new
27
49
  args = Array(args)
@@ -39,6 +61,8 @@ module Hanami
39
61
  result
40
62
  end
41
63
 
64
+ # @since 0.2.0
65
+ # @api private
42
66
  def _redefine_call
43
67
  return if @parsers.empty?
44
68
 
@@ -56,6 +80,7 @@ module Hanami
56
80
  end
57
81
  end
58
82
 
83
+ # @api private
59
84
  def _symbolize(body)
60
85
  if body.is_a?(Hash)
61
86
  Utils::Hash.new(body).deep_dup.deep_symbolize!.to_h
@@ -64,18 +89,21 @@ module Hanami
64
89
  end
65
90
  end
66
91
 
92
+ # @api private
67
93
  def _parse(env, body)
68
94
  @parsers[
69
95
  media_type(env)
70
96
  ].parse(body)
71
97
  end
72
98
 
99
+ # @api private
73
100
  def media_type(env)
74
101
  if ct = content_type(env)
75
102
  ct.split(MEDIA_TYPE_MATCHER, 2).first.downcase
76
103
  end
77
104
  end
78
105
 
106
+ # @api private
79
107
  def content_type(env)
80
108
  content_type = env[CONTENT_TYPE]
81
109
  content_type.nil? || content_type.empty? ? nil : content_type
@@ -3,7 +3,11 @@ require 'hanami/utils/json'
3
3
  module Hanami
4
4
  module Routing
5
5
  module Parsing
6
+ # @since 0.2.0
7
+ # @api private
6
8
  class JsonParser < Parser
9
+ # @since 0.2.0
10
+ # @api private
7
11
  def mime_types
8
12
  ['application/json', 'application/vnd.api+json']
9
13
  end
@@ -17,6 +21,7 @@ module Hanami
17
21
  # @raise [Hanami::Routing::Parsing::BodyParsingError] when the body can't be parsed.
18
22
  #
19
23
  # @since 0.2.0
24
+ # @api private
20
25
  def parse(body)
21
26
  Hanami::Utils::Json.parse(body)
22
27
  rescue Hanami::Utils::Json::ParserError => e
@@ -14,6 +14,8 @@ module Hanami
14
14
 
15
15
  # @since 0.2.0
16
16
  class UnknownParserError < Hanami::Routing::Error
17
+ # @since 0.2.0
18
+ # @api private
17
19
  def initialize(parser)
18
20
  super("Unknown Parser: `#{ parser }'")
19
21
  end
@@ -22,6 +24,7 @@ module Hanami
22
24
  # @since 0.2.0
23
25
  class Parser
24
26
  # @since 0.2.0
27
+ # @api private
25
28
  def self.for(parser)
26
29
  case parser
27
30
  when String, Symbol
@@ -96,6 +96,7 @@ module Hanami
96
96
  klass.new(@router, [@name, name].join(NESTED_ROUTES_SEPARATOR), options, self, &blk)
97
97
  end
98
98
 
99
+ # @api private
99
100
  def generate(&blk)
100
101
  instance_eval(&blk) if block_given?
101
102
 
@@ -104,10 +105,12 @@ module Hanami
104
105
  end
105
106
  end
106
107
 
108
+ # @api private
107
109
  def member(&blk)
108
110
  self.class.member.new(@router, @options, self, &blk)
109
111
  end
110
112
 
113
+ # @api private
111
114
  def collection(&blk)
112
115
  self.class.collection.new(@router, @options, self, &blk)
113
116
  end
@@ -280,11 +280,15 @@ module Hanami
280
280
  # @since 0.1.0
281
281
  # @see Hanami::Router#resource
282
282
  class CollectionAction < Action
283
+ # @since 0.1.0
284
+ # @api private
283
285
  def generate(&blk)
284
286
  instance_eval(&blk) if block_given?
285
287
  end
286
288
 
287
289
  protected
290
+ # @since 0.1.0
291
+ # @api private
288
292
  def method_missing(m, *args)
289
293
  verb = m
290
294
  action_name = Utils::PathPrefix.new(args.first).relative_join(nil)
@@ -294,14 +298,20 @@ module Hanami
294
298
  end
295
299
 
296
300
  private
301
+ # @since 0.1.0
302
+ # @api private
297
303
  def path(action_name)
298
304
  rest_path.join(action_name)
299
305
  end
300
306
 
307
+ # @since 0.1.0
308
+ # @api private
301
309
  def endpoint(action_name)
302
310
  [ controller_name, action_name ].join separator
303
311
  end
304
312
 
313
+ # @since 0.1.0
314
+ # @api private
305
315
  def as(action_name)
306
316
  [ action_name, super() ].join(self.class.named_route_separator).to_sym
307
317
  end
@@ -322,10 +332,14 @@ module Hanami
322
332
  # @since 0.1.0
323
333
  module DefaultMemberAction
324
334
  private
335
+ # @since 0.1.0
336
+ # @api private
325
337
  def path
326
338
  rest_path.join(action_name)
327
339
  end
328
340
 
341
+ # @since 0.1.0
342
+ # @api private
329
343
  def as
330
344
  [ action_name, super ].join(self.class.named_route_separator).to_sym
331
345
  end
@@ -28,6 +28,8 @@ module Hanami
28
28
 
29
29
  private
30
30
 
31
+ # @api private
32
+ # @since 0.4.0
31
33
  def _calculate(param_wildcard, resource = nil)
32
34
  return if resource.nil?
33
35
  @path << resource.wildcard_param(param_wildcard.pop)
@@ -62,6 +62,8 @@ module Hanami
62
62
  # @see Hanami::Router#resources
63
63
  class MemberAction < Resource::MemberAction
64
64
  private
65
+ # @since 0.1.0
66
+ # @api private
65
67
  def path(action_name)
66
68
  rest_path.join(Action.identifier, action_name)
67
69
  end
@@ -73,6 +75,8 @@ module Hanami
73
75
  # @since 0.1.0
74
76
  module DefaultMemberAction
75
77
  private
78
+ # @since 0.1.0
79
+ # @api private
76
80
  def path
77
81
  rest_path.join(Action.identifier)
78
82
  end
@@ -123,6 +127,8 @@ module Hanami
123
127
  include DefaultMemberAction
124
128
 
125
129
  private
130
+ # @since 0.1.0
131
+ # @api private
126
132
  def path
127
133
  super.join(action_name)
128
134
  end
@@ -7,6 +7,7 @@ module Hanami
7
7
  # @api private
8
8
  #
9
9
  # @since 0.1.0
10
+ # @api private
10
11
  #
11
12
  # @see http://rdoc.info/gems/http_router/HttpRouter/Route
12
13
  #
@@ -61,6 +62,7 @@ module Hanami
61
62
  end
62
63
 
63
64
  private
65
+ # @api private
64
66
  def to=(dest = nil, &blk)
65
67
  self.to dest, &blk
66
68
  end
@@ -60,6 +60,7 @@ module Hanami
60
60
  # @return [String] routes pretty print
61
61
  #
62
62
  # @since 0.2.0
63
+ # @api private
63
64
  #
64
65
  # @see Hanami::Routing::RoutesInspector::FORMATTER
65
66
  #
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: 1.0.0.beta2
4
+ version: 1.0.0.beta3
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: 2017-03-02 00:00:00.000000000 Z
13
+ date: 2017-03-17 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rack