cotton-tail 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Gemfile.lock +1 -1
- data/lib/cotton_tail.rb +4 -0
- data/lib/cotton_tail/dsl/routes.rb +1 -1
- data/lib/cotton_tail/middleware.rb +0 -1
- data/lib/cotton_tail/middleware/router.rb +17 -2
- data/lib/cotton_tail/route.rb +36 -0
- data/lib/cotton_tail/version.rb +1 -1
- metadata +3 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea50d4559d3b22547293d0efb07f7841837e272b877a96646c948a2d125313a8
|
4
|
+
data.tar.gz: 640b18d1aefc48686535b9f1f3685c38c5fc1724492192bb766dfdd39573d0ca
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 433de64af1c506e5f997e7cd24c70453110822662b6ba5139673b443bff235100a15d6dad2f1e3e23f0e429cab08dd927c0c47b614094b3f0160893ee6644541
|
7
|
+
data.tar.gz: 18a12763f6a88ab0940c20850e1110b0a4305f69451f5ef2ef2c7a5f82ec1f59bf48e41dccc8e9740da3854314c3c82c4c84a50d0878ae94c662617c2fa434bc
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/Gemfile.lock
CHANGED
data/lib/cotton_tail.rb
CHANGED
@@ -9,6 +9,7 @@ module CottonTail
|
|
9
9
|
autoload :DSL, 'cotton_tail/dsl'
|
10
10
|
autoload :Middleware, 'cotton_tail/middleware'
|
11
11
|
autoload :Queue, 'cotton_tail/queue'
|
12
|
+
autoload :Route, 'cotton_tail/route'
|
12
13
|
autoload :Router, 'cotton_tail/router'
|
13
14
|
autoload :Version, 'cotton_tail/version'
|
14
15
|
|
@@ -28,6 +29,9 @@ module CottonTail
|
|
28
29
|
|
29
30
|
Response = Struct.new(:body)
|
30
31
|
|
32
|
+
class RouteConflictError < StandardError
|
33
|
+
end
|
34
|
+
|
31
35
|
class UndefinedRouteError < StandardError
|
32
36
|
end
|
33
37
|
end
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'json'
|
4
|
+
|
3
5
|
module CottonTail
|
4
6
|
module Middleware
|
5
7
|
# Router Middleware
|
@@ -18,13 +20,26 @@ module CottonTail
|
|
18
20
|
|
19
21
|
private
|
20
22
|
|
21
|
-
def
|
22
|
-
|
23
|
+
def route(routing_key)
|
24
|
+
CottonTail::Route.new(routing_key)
|
23
25
|
end
|
24
26
|
|
25
27
|
def response(routing_key, message)
|
26
28
|
CottonTail::Response.new handler(routing_key).call(message)
|
27
29
|
end
|
30
|
+
|
31
|
+
def routes(routing_key)
|
32
|
+
handlers.keys.select { |route| route.match? routing_key }
|
33
|
+
end
|
34
|
+
|
35
|
+
def handler(routing_key)
|
36
|
+
route, *conflicts = routes(routing_key)
|
37
|
+
raise UndefinedRouteError if route.nil?
|
38
|
+
|
39
|
+
raise RouteConflictError unless conflicts.empty?
|
40
|
+
|
41
|
+
handlers[route]
|
42
|
+
end
|
28
43
|
end
|
29
44
|
end
|
30
45
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module CottonTail
|
4
|
+
# Route value object
|
5
|
+
class Route
|
6
|
+
attr_reader :pattern
|
7
|
+
|
8
|
+
def initialize(pattern)
|
9
|
+
@pattern = pattern
|
10
|
+
end
|
11
|
+
|
12
|
+
def match?(routing_key)
|
13
|
+
return true if @pattern == routing_key
|
14
|
+
|
15
|
+
regex.match? routing_key
|
16
|
+
end
|
17
|
+
|
18
|
+
def to_s
|
19
|
+
@pattern
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def regex
|
25
|
+
@regex ||= Regexp.new build_regex(@pattern)
|
26
|
+
end
|
27
|
+
|
28
|
+
def build_regex(pattern)
|
29
|
+
[
|
30
|
+
'^',
|
31
|
+
pattern.gsub('*', '([^.]+)').gsub(/\.?#\.?/, '([^.]{0,}\.?)+'),
|
32
|
+
'$'
|
33
|
+
].join
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/cotton_tail/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cotton-tail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Brennan
|
@@ -30,7 +30,7 @@ cert_chain:
|
|
30
30
|
fXe/xr/Sc+2wCjHPVE2J+auN5hk3KCp1I4s2fKqyLIwyhTEF3shuYfCpC8rt/YdN
|
31
31
|
cy9/lg5LCI3OvakzxL4Xt1Sq4h/xJZ06ydTVJ1wxfk6BXHrg
|
32
32
|
-----END CERTIFICATE-----
|
33
|
-
date: 2018-12-
|
33
|
+
date: 2018-12-13 00:00:00.000000000 Z
|
34
34
|
dependencies:
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
36
|
name: bunny
|
@@ -219,6 +219,7 @@ files:
|
|
219
219
|
- lib/cotton_tail/queue/memory.rb
|
220
220
|
- lib/cotton_tail/queue/reader.rb
|
221
221
|
- lib/cotton_tail/queue/supervisor.rb
|
222
|
+
- lib/cotton_tail/route.rb
|
222
223
|
- lib/cotton_tail/version.rb
|
223
224
|
homepage: https://github.com/jamesBrennan/cotton-tail
|
224
225
|
licenses:
|
metadata.gz.sig
CHANGED
Binary file
|