galago-router 0.1.0 → 0.1.1
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 +4 -4
- data/lib/galago/router/dsl.rb +1 -7
- data/lib/galago/router/path.rb +10 -0
- data/lib/galago/router/version.rb +1 -1
- data/spec/galago/router/path_spec.rb +17 -0
- data/spec/galago/router/version_spec.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ca65e8d3da9c0e6e460c0b264402285bd9d2dfa
|
4
|
+
data.tar.gz: 774adf1034c62b50bd690092cc6e1efc6e9dccaf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e72781d341817aada32d6f133fecb622e6f58954491acbfdc3d5f7698301b8e8cd189addc592195478c431a9cc4cbffa4fa7539fb009baa8182eed08c25e1eeb
|
7
|
+
data.tar.gz: 8db3316782ebb5076861c3701db5ff52bd7ab6b51363d8ba87513cbf702457ec48978cf88f7f4a12badbec04571889ba7c493eef54962c33645d28c2be6a05bf
|
data/lib/galago/router/dsl.rb
CHANGED
@@ -36,16 +36,10 @@ module Galago
|
|
36
36
|
private
|
37
37
|
|
38
38
|
def add_route(method, path, application)
|
39
|
-
path_with_namespace =
|
39
|
+
path_with_namespace = Path.join(@namespace, path)
|
40
40
|
@router.add_route(method, path_with_namespace, application)
|
41
41
|
end
|
42
42
|
|
43
|
-
def add_namespace_to_path(path)
|
44
|
-
path = "#{@namespace}/#{path}"
|
45
|
-
path = path.gsub('//', '/')
|
46
|
-
path = path.gsub(/\/$/, '')
|
47
|
-
path
|
48
|
-
end
|
49
43
|
end
|
50
44
|
end
|
51
45
|
end
|
data/lib/galago/router/path.rb
CHANGED
@@ -2,6 +2,16 @@ module Galago
|
|
2
2
|
class Router
|
3
3
|
class Path
|
4
4
|
|
5
|
+
REPEATED_SLASH = /\/{1,}/
|
6
|
+
TRAILING_SLASH = /\/$/
|
7
|
+
|
8
|
+
def self.join(*paths)
|
9
|
+
path = "/#{paths.join('/')}"
|
10
|
+
path = path.gsub(REPEATED_SLASH, '/')
|
11
|
+
path = path.gsub(TRAILING_SLASH, '')
|
12
|
+
path
|
13
|
+
end
|
14
|
+
|
5
15
|
def initialize(path)
|
6
16
|
@path = path.to_s
|
7
17
|
end
|
@@ -3,6 +3,23 @@ require 'spec_helper'
|
|
3
3
|
module Galago
|
4
4
|
describe Router::Path do
|
5
5
|
|
6
|
+
describe ".join" do
|
7
|
+
it "joins the provided segments with a '/'" do
|
8
|
+
path = Router::Path.join('foo', 'bar')
|
9
|
+
expect(path).to eql '/foo/bar'
|
10
|
+
end
|
11
|
+
|
12
|
+
it "removes repeated '/'" do
|
13
|
+
path = Router::Path.join('//foo', '///bar', '/baz')
|
14
|
+
expect(path).to eql '/foo/bar/baz'
|
15
|
+
end
|
16
|
+
|
17
|
+
it "removes trailing '/'" do
|
18
|
+
path = Router::Path.join('foo', 'bar/')
|
19
|
+
expect(path).to eql '/foo/bar'
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
6
23
|
describe "#recognizes?" do
|
7
24
|
it "recognizes exact matches" do
|
8
25
|
path = Router::Path.new('/users')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: galago-router
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe Karayusuf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-03-
|
11
|
+
date: 2014-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|