soar_sc-rack-router 1.0.0 → 2.0.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: 06db72006f7280dbcdfd881a108d084e9fb67b79
4
- data.tar.gz: 4ffcd46d095e341fce59740dad5a6faaa3ed8552
3
+ metadata.gz: 7c3e14ae23f2f9217563a57239e82ec930382ec1
4
+ data.tar.gz: 6ab1b6bf12582996334481f2aa06a90cb0447c55
5
5
  SHA512:
6
- metadata.gz: 1962096dc371cc19ce1d25bde13a0724f9d934006bcf0a0c36036f7bc3b762a2154025effb39aa52aa8f90c2b5a024ddf502e22d8683c3f27376e5bfb38122f2
7
- data.tar.gz: c7b0b28b6ec325022474b76bff8194de423beb484b185eba8516d7c9549eaaea0a60c16bbbda5a20793ad883663ca2201af1d38116313a3d877426dd30f7bc50
6
+ metadata.gz: 1593840d3ea7254eb74ce64dd95bf8d3ea2a984821117bd3a802da50a81ef8b5cdc71a66c3d1aca4b4b57d517498456d2753f7ed53ce696c0ee33fbeb7aecc17
7
+ data.tar.gz: c0572f514f065db5b65dd22a841459323899a49f186ccf0f3f7242c739ccf7ba475dd7de13ced12dcb257d84c6feba783c51ed86790155b66ba0a9b8f49262db
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Gem Version](https://badge.fury.io/rb/soar_sc-rack-router.svg)](http://badge.fury.io/rb/soar_sc-rack-router) [![Build Status](https://travis-ci.org/hetznerZA/soar_sc-rack-router.svg?branch=master)](https://travis-ci.org/hetznerZA/soar_sc-rack-router)
2
+
1
3
  # SoarSc::Rack::Router
2
4
 
3
5
  SoarSc::Rack::Router is a middleware-centric rack router. It has three key features:
@@ -18,24 +18,11 @@ module SoarSc
18
18
  def initialize(method, path, action)
19
19
  validate_path(path)
20
20
  @method, @path, @action = method, path, action
21
- @static = components(path).none? { |c| c.start_with?(PARAMETER_PREFIX) }
21
+ @static = components(@path).none? { |c| c.start_with?(PARAMETER_PREFIX) }
22
22
  end
23
23
 
24
24
  def matches?(env)
25
- return false unless method == env[REQUEST_METHOD] or method == HttpMethod::ANY
26
-
27
- return request_path(env) == path if @static
28
-
29
- route_components = components(path)
30
- req_components = components(request_path(env))
31
-
32
- return false unless route_components.size == req_components.size
33
-
34
- route_components.each_with_index do |c, i|
35
- return false unless c.start_with?(PARAMETER_PREFIX) or c == req_components[i]
36
- end
37
-
38
- return true
25
+ method_matches?(env[REQUEST_METHOD]) and path_matches?(request_path(env))
39
26
  end
40
27
 
41
28
  def extract_path_parameters(env)
@@ -43,7 +30,7 @@ module SoarSc
43
30
 
44
31
  req_components = components(request_path(env))
45
32
  parameters = {}
46
- components(path).each_with_index do |c, i|
33
+ components(@path).each_with_index do |c, i|
47
34
  parameters[c[1..-1]] = req_components[i] if c.start_with?(PARAMETER_PREFIX)
48
35
  end
49
36
  parameters
@@ -51,6 +38,35 @@ module SoarSc
51
38
 
52
39
  private
53
40
 
41
+ def method_matches?(method)
42
+ @method == method or @method == HttpMethod::ANY
43
+ end
44
+
45
+ def path_matches?(path)
46
+ if @static
47
+ static_path_matches?(path)
48
+ else
49
+ parameterized_path_matches?(path)
50
+ end
51
+ end
52
+
53
+ def static_path_matches?(path)
54
+ path == @path
55
+ end
56
+
57
+ def parameterized_path_matches?(path)
58
+ route_components = components(@path)
59
+ req_components = components(path)
60
+
61
+ return false unless route_components.size == req_components.size
62
+
63
+ route_components.each_with_index do |c, i|
64
+ return false unless c.start_with?(PARAMETER_PREFIX) or c == req_components[i]
65
+ end
66
+
67
+ return true
68
+ end
69
+
54
70
  def request_path(env)
55
71
  env[SCRIPT_NAME] + env[PATH_INFO]
56
72
  end
@@ -1,7 +1,7 @@
1
1
  module SoarSc
2
2
  module Rack
3
3
  class Router
4
- VERSION = "1.0.0"
4
+ VERSION = "2.0.0"
5
5
  end
6
6
  end
7
7
  end
@@ -14,10 +14,12 @@ module SoarSc
14
14
 
15
15
  EMPTY_STRING = ""
16
16
 
17
- def initialize(app, routes = {}, &block)
17
+ def initialize(app, routes = nil, &block)
18
18
  @app = app
19
19
  @routes = []
20
- routes.each { |(p, a)| add_route(Route.new(HttpMethod::ANY, p, a)) }
20
+ if !routes.nil?
21
+ raise NotImplementedError, "Route map syntax obsoleted (use builder syntax)"
22
+ end
21
23
  instance_eval(&block) if block_given?
22
24
  end
23
25
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: soar_sc-rack-router
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sheldon Hearn