rack-app 7.0.0 → 7.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 15de58a9bddb3a5eee2b5e9d926db27f95353d7a
4
- data.tar.gz: 34f5a7ea36d028691ec5e5da7d1d1d7d83526687
3
+ metadata.gz: 98195c15403a0ea4553dc9ab1b3715330022890d
4
+ data.tar.gz: 188df7a9406b8629636bc62ae7b2d67165b6cfc2
5
5
  SHA512:
6
- metadata.gz: 1db484ffb9f9d89c524e5cabb7e9f6ebeaf2fcc4bbf71690f07ae3796471f233f8e63ebcd884ef756ba9aaaa4005c973c5d28267e9f4dfe3cd4c0ee44054dd4f
7
- data.tar.gz: 9e0c07fcb2133bdc264df3532aa1a3fea7eb6feede5ffa8d52b71dc52007210cb2cca9916b6577ab09bec949e3b31e07808a3411122bad41d6943f592c3804cb
6
+ metadata.gz: c7eb246de327c5786c66ecbc3937e6b1b9272ccab6322a9deb064b6eca37f75d16ff504f3b3b3e5d1ed8f3f0e1002e07a027458ed5c1a0cfd6ebb0b7081c005a
7
+ data.tar.gz: 91ea8cc869ceb51aa1b4e2ee3a5ed0ada04b9ed3c1fdb0dfa06c3030cea129328cfd3abf07a4be9da4631a212c7a45b5c8cf00f6a7f8ff429bb1cb1d27c35cb8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 7.0.0
1
+ 7.1.0
@@ -1,10 +1,10 @@
1
1
  class Rack::App::Router
2
-
3
2
  require 'rack/app/router/tree'
3
+ require 'rack/app/router/error'
4
4
 
5
5
  attr_reader :tree
6
6
 
7
- NOT_FOUND_APP = lambda do |env|
7
+ NOT_FOUND_APP = lambda do |_env|
8
8
  rack_response = Rack::Response.new
9
9
  rack_response.status = 404
10
10
  rack_response.write('404 Not Found')
@@ -12,7 +12,7 @@ class Rack::App::Router
12
12
  end
13
13
 
14
14
  def call(env)
15
- env[Rack::App::Constants::ENV::ROUTER]= self
15
+ env[Rack::App::Constants::ENV::ROUTER] = self
16
16
  @tree.call(env) || NOT_FOUND_APP.call(env)
17
17
  end
18
18
 
@@ -23,18 +23,18 @@ class Rack::App::Router
23
23
  def register_endpoint!(endpoint)
24
24
  endpoints.push(endpoint)
25
25
  compile_endpoint!(endpoint)
26
- return endpoint
26
+ endpoint
27
27
  end
28
28
 
29
29
  # add ! to method name
30
30
  def reset
31
- @lookup_paths = Hash.new #(Hash.new)
31
+ @lookup_paths = {} # (Hash.new)
32
32
  @tree = Rack::App::Router::Tree.new
33
33
  compile_registered_endpoints!
34
34
  end
35
35
 
36
36
  # rename to merge!
37
- def merge_router!(router, prop={})
37
+ def merge_router!(router, prop = {})
38
38
  raise(ArgumentError, 'invalid router object, must implement :endpoints interface') unless router.respond_to?(:endpoints)
39
39
  router.endpoints.each do |endpoint|
40
40
  new_request_path = ::Rack::App::Utils.join(prop[:namespaces], endpoint.request_path)
@@ -45,27 +45,26 @@ class Rack::App::Router
45
45
  nil
46
46
  end
47
47
 
48
-
49
48
  def show_endpoints
50
-
51
49
  endpoints = self.endpoints
52
50
 
53
51
  wd0 = endpoints.map { |endpoint| endpoint.request_method.to_s.length }.max
54
52
  wd1 = endpoints.map { |endpoint| endpoint.request_path.to_s.length }.max
55
53
  wd2 = endpoints.map { |endpoint| endpoint.description.to_s.length }.max
56
54
 
57
- return endpoints.sort_by { |endpoint| [endpoint.request_method, endpoint.request_path] }.map do |endpoint|
55
+ endpoints.sort_by { |endpoint| [endpoint.request_method, endpoint.request_path] }.map do |endpoint|
58
56
  [
59
57
  endpoint.request_method.to_s.ljust(wd0),
60
58
  endpoint.request_path.to_s.ljust(wd1),
61
59
  endpoint.description.to_s.ljust(wd2)
62
60
  ].join(' ')
63
61
  end
64
-
65
62
  end
66
63
 
67
64
  def path_to(klass, defined_path)
68
- (@lookup_paths[klass][defined_path] || raise("missing path reference")).dup
65
+ @lookup_paths[klass] || raise(self.class::Error::AppIsNotMountedInTheRouter, "#{klass} is not registered in the router")
66
+ found_path = @lookup_paths[klass][defined_path] || raise(self.class::Error::MountedAppDoesNotHaveThisPath, 'missing path reference')
67
+ found_path.dup
69
68
  end
70
69
 
71
70
  protected
@@ -90,7 +89,6 @@ class Rack::App::Router
90
89
  def_path = endpoint.config.defined_request_path
91
90
  final_path = endpoint.request_path
92
91
  dictionary = @lookup_paths[endpoint.config.app_class] ||= {}
93
- dictionary[def_path]= final_path
92
+ dictionary[def_path] = final_path
94
93
  end
95
-
96
94
  end
@@ -0,0 +1,4 @@
1
+ class Rack::App::Router::Error < StandardError
2
+ AppIsNotMountedInTheRouter = Class.new(self)
3
+ MountedAppDoesNotHaveThisPath = Class.new(self)
4
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 7.0.0
4
+ version: 7.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-24 00:00:00.000000000 Z
11
+ date: 2017-07-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -153,6 +153,7 @@ files:
153
153
  - lib/rack/app/request_configurator.rb
154
154
  - lib/rack/app/request_stream.rb
155
155
  - lib/rack/app/router.rb
156
+ - lib/rack/app/router/error.rb
156
157
  - lib/rack/app/router/tree.rb
157
158
  - lib/rack/app/router/tree/branch.rb
158
159
  - lib/rack/app/router/tree/env.rb