proximity 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +4 -1
- data/Gemfile +1 -0
- data/README.md +13 -1
- data/lib/proximity/proxy.rb +11 -2
- data/lib/proximity/proxy_set.rb +2 -3
- data/lib/proximity/version.rb +1 -1
- data/lib/proximity.rb +1 -0
- data/spec/proximity/proxy_set_spec.rb +6 -6
- data/spec/proximity/proxy_spec.rb +6 -1
- data/spec/spec_helper.rb +11 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57061cf9b5b09837dec718504fe8fbfa6c2488f4
|
4
|
+
data.tar.gz: f1000c4fc3f1653b409c68845e6fc63f268d064d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 601a50c2cf27e9f9b84e67897895eff2c0af315d7ba5e36720b37950c1e2150e2ffd482aef4f4b9bb59d9bd188be24c03e49d1bb47999d2d9c09e9aa0ef67d14
|
7
|
+
data.tar.gz: 75c5ab092c4c5a4fb78c1f3b643e263948bc78eff9c06373d5e2d2fba5015bb969bf5df4fcee79a3aec1b4134754bf65270b8be2ff47c77b03c2079957318939
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,6 +4,12 @@
|
|
4
4
|
[`Journey`](https://github.com/rails/journey) for routing. `Journey` is
|
5
5
|
vendored into `ActionPack` as of [`Rails`](https://github.com/rails/rails/tree/master/actionpack/lib/action_dispatch/journey)4.
|
6
6
|
|
7
|
+
[![Gem Version](https://badge.fury.io/rb/proximity.png)](http://badge.fury.io/rb/proximity)
|
8
|
+
[![Code Climate](https://codeclimate.com/github/adamhunter/proximity.png)](https://codeclimate.com/github/adamhunter/proximity)
|
9
|
+
[![Build Status](https://travis-ci.org/adamhunter/proximity.png?branch=master)](https://travis-ci.org/adamhunter/proximity)
|
10
|
+
[![Coverage Status](https://coveralls.io/repos/adamhunter/proximity/badge.png)](https://coveralls.io/r/adamhunter/proximity)
|
11
|
+
[![Dependency Status](https://gemnasium.com/adamhunter/proximity.png)](https://gemnasium.com/adamhunter/proximity)
|
12
|
+
|
7
13
|
## Usage
|
8
14
|
1. Create your own subclass of `Rack::Proxy`.
|
9
15
|
2. `include Proximity` into that class.
|
@@ -17,12 +23,18 @@ vendored into `ActionPack` as of [`Rails`](https://github.com/rails/rails/tree/m
|
|
17
23
|
## Example
|
18
24
|
```ruby
|
19
25
|
# my_proxy.rb
|
20
|
-
class MyProxy <
|
26
|
+
class MyProxy < Rack::Proxy
|
21
27
|
include Proximity
|
22
28
|
end
|
23
29
|
|
24
30
|
# proxies.rb
|
25
31
|
MyProxy.routes.draw do
|
32
|
+
route 'example' => 'example.com/api' do
|
33
|
+
proxy 'active' => 'accounts/active'
|
34
|
+
proxy 'accounts' => same, formats %w[json csv]
|
35
|
+
proxy 'accounts/:account_id' => same
|
36
|
+
proxy 'crazy/:id/:account_id' => 'fluffy/kitties/:id-:account_id'
|
37
|
+
end
|
26
38
|
end
|
27
39
|
```
|
28
40
|
|
data/lib/proximity/proxy.rb
CHANGED
@@ -7,11 +7,11 @@ module Proximity
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def target
|
10
|
-
with_format "#{route_set.target}#{
|
10
|
+
with_format "#{route_set.target}#{slashify determine_target}"
|
11
11
|
end
|
12
12
|
|
13
13
|
def source
|
14
|
-
with_format "#{route_set.source}#{@source}"
|
14
|
+
with_format "#{route_set.source}#{slashify @source}"
|
15
15
|
end
|
16
16
|
|
17
17
|
def pattern
|
@@ -24,10 +24,19 @@ module Proximity
|
|
24
24
|
|
25
25
|
private
|
26
26
|
|
27
|
+
def slashify(path)
|
28
|
+
return if path.blank?
|
29
|
+
"/#{path}"
|
30
|
+
end
|
31
|
+
|
27
32
|
def with_format(url)
|
28
33
|
format.nil? ? url : "#{url}.#{format}"
|
29
34
|
end
|
30
35
|
|
36
|
+
def determine_target
|
37
|
+
@target == Same ? @source : @target
|
38
|
+
end
|
39
|
+
|
31
40
|
attr_reader :route_set
|
32
41
|
|
33
42
|
Same = Class.new
|
data/lib/proximity/proxy_set.rb
CHANGED
@@ -43,14 +43,13 @@ module Proximity
|
|
43
43
|
end
|
44
44
|
|
45
45
|
def normalize_source(source)
|
46
|
-
source
|
47
|
-
source = source.ends_with?('/') ? source : "#{source}/"
|
46
|
+
source.starts_with?('/') ? source : "/#{source}"
|
48
47
|
end
|
49
48
|
|
50
49
|
def normalize_target(target)
|
51
50
|
uri = URI.parse(target)
|
52
51
|
target = uri.scheme.nil? ? "#{self.class.default_scheme}://#{target}" : target
|
53
|
-
env_tld target
|
52
|
+
env_tld target
|
54
53
|
end
|
55
54
|
|
56
55
|
def env_tld(url)
|
data/lib/proximity/version.rb
CHANGED
data/lib/proximity.rb
CHANGED
@@ -8,11 +8,11 @@ describe Proximity::ProxySet do
|
|
8
8
|
let(:proxy) { route.proxy }
|
9
9
|
|
10
10
|
it "will set the source prefix on the route set" do
|
11
|
-
expect(proxy_set.source).to eq('/example
|
11
|
+
expect(proxy_set.source).to eq('/example')
|
12
12
|
end
|
13
13
|
|
14
14
|
it "will set the target prefix on the route set" do
|
15
|
-
expect(proxy_set.target).to eq('http://example.local/api
|
15
|
+
expect(proxy_set.target).to eq('http://example.local/api')
|
16
16
|
end
|
17
17
|
|
18
18
|
it "will create a route with the given prefix for its source" do
|
@@ -26,7 +26,7 @@ describe Proximity::ProxySet do
|
|
26
26
|
|
27
27
|
describe "protocol" do
|
28
28
|
it "will be added to the target prefix if missing" do
|
29
|
-
expect(proxy_set.target).to eq('http://example.local/api
|
29
|
+
expect(proxy_set.target).to eq('http://example.local/api')
|
30
30
|
end
|
31
31
|
|
32
32
|
it "will not add a protocol if provided in the target prefix" do
|
@@ -44,7 +44,7 @@ describe Proximity::ProxySet do
|
|
44
44
|
let(:environment) { 'development' }
|
45
45
|
|
46
46
|
it "will convert .com into .local" do
|
47
|
-
expect(proxy_set.target).to eq('http://example.local/api
|
47
|
+
expect(proxy_set.target).to eq('http://example.local/api')
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
@@ -52,7 +52,7 @@ describe Proximity::ProxySet do
|
|
52
52
|
let(:environment) { 'test' }
|
53
53
|
|
54
54
|
it "will convert .com into .local" do
|
55
|
-
expect(proxy_set.target).to eq('http://example.local/api
|
55
|
+
expect(proxy_set.target).to eq('http://example.local/api')
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
@@ -60,7 +60,7 @@ describe Proximity::ProxySet do
|
|
60
60
|
let(:environment) { 'production' }
|
61
61
|
|
62
62
|
it "will not convert .com into .local" do
|
63
|
-
expect(proxy_set.target).to eq('http://example.com/api
|
63
|
+
expect(proxy_set.target).to eq('http://example.com/api')
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -5,11 +5,16 @@ describe Proximity::Proxy do
|
|
5
5
|
let(:route) { router.routes[0].proxy }
|
6
6
|
let(:same) { router.routes[1].proxy }
|
7
7
|
let(:format) { router.routes[2].proxy }
|
8
|
+
let(:blank) { router.routes[6].proxy }
|
8
9
|
|
9
|
-
it "prefixes the source with the route set source" do
|
10
|
+
it "prefixes the source with the route set source and a slash" do
|
10
11
|
expect(route.source).to eq('/example/active')
|
11
12
|
end
|
12
13
|
|
14
|
+
it "does not add a slash to the route set source if source is blank" do
|
15
|
+
expect(blank.source). to eq('/example')
|
16
|
+
end
|
17
|
+
|
13
18
|
it "prefixes the target with the route set target" do
|
14
19
|
expect(route.target).to eq('http://example.local/api/are/you/active')
|
15
20
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -2,6 +2,16 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
|
2
2
|
require 'proximity'
|
3
3
|
require 'rack/proxy'
|
4
4
|
require 'pry'
|
5
|
+
require 'simplecov'
|
6
|
+
require 'coveralls'
|
7
|
+
|
8
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
9
|
+
SimpleCov::Formatter::HTMLFormatter,
|
10
|
+
Coveralls::SimpleCov::Formatter
|
11
|
+
]
|
12
|
+
|
13
|
+
SimpleCov.start
|
14
|
+
Coveralls.wear!
|
5
15
|
|
6
16
|
class SpecProxy < Rack::Proxy
|
7
17
|
include Proximity
|
@@ -22,6 +32,7 @@ def mock_routes
|
|
22
32
|
proxy 'accounts' => same, formats: %w[json csv]
|
23
33
|
proxy 'accounts/:account_id' => same
|
24
34
|
proxy 'accounts/:account_id/members/:member_id' => 'accounts-members/:account_id-:member_id'
|
35
|
+
proxy '' => same
|
25
36
|
end
|
26
37
|
end
|
27
38
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: proximity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Hunter
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: actionpack
|
@@ -148,7 +148,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
148
148
|
version: '0'
|
149
149
|
requirements: []
|
150
150
|
rubyforge_project:
|
151
|
-
rubygems_version: 2.0.
|
151
|
+
rubygems_version: 2.0.3
|
152
152
|
signing_key:
|
153
153
|
specification_version: 4
|
154
154
|
summary: Proximity provides a router to applications utilizing Rack::Proxy to coordinate
|