restify 0.1.2.1.b40 → 0.1.2.1.b41
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/restify/relation.rb +13 -4
- data/spec/restify/relation_spec.rb +21 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
OWUzY2Q1OGUzZDI1YTdhM2Q5YTExMTI1YmY2ZmFiMDkxNzAwZjU0YQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZDcyMTAxMzdlMjFjOGNiOGYzMGRjYzQ5ZmQyOTc2MTllMDg2ZGY3Ng==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
ODI0MTdmYmMzYWVmZmI2MDAyY2ZhMTllZjllMGZkNGIxNzkyYWQ3ODllYTkw
|
10
|
+
ZWQ1MjZiMTg2NGJkYTFiZjJhZDQwODExNGFmOTZhMjFiMGJkOTM4ZjAzMWIy
|
11
|
+
MDNkMWM2MTk0YjAyYzdmMzc0YjFkZWI5MGU1YTdmNzU5ZTIyNmQ=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NTYxMGJkYWRjZjMzOWQ5NGQ0N2U5ZDdmZDRmNTExMWIwYWJjNTY0ZjA0ZGIw
|
14
|
+
ODdlMzRhZTI1MDFjZWYyYTE4YmU1MjMzOTViMmIyNzRmNDk3NWU3NjMzMGZi
|
15
|
+
ODVjMzJmZjIyODdlMGYzNmZmYWJkYWVhNGViMGM4MWMwODU1MWU=
|
data/lib/restify/relation.rb
CHANGED
@@ -33,14 +33,23 @@ module Restify
|
|
33
33
|
(other.is_a?(String) && @source == other)
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
def expand(params)
|
37
|
+
@template.expand extracted params
|
38
|
+
end
|
37
39
|
|
38
|
-
|
40
|
+
private
|
39
41
|
|
40
42
|
def request(method, data, params)
|
41
|
-
|
43
|
+
@context.request method, expand(params), data
|
44
|
+
end
|
42
45
|
|
43
|
-
|
46
|
+
def extracted(params)
|
47
|
+
@template.variables.each_with_object({}) do |var, hash|
|
48
|
+
if (value = params.delete(var) { params.delete(var.to_sym) { nil }})
|
49
|
+
value = value.to_param if value.respond_to?(:to_param)
|
50
|
+
hash[var] = value
|
51
|
+
end
|
52
|
+
end
|
44
53
|
end
|
45
54
|
|
46
55
|
def to_template(pattern)
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Restify::Relation do
|
4
4
|
let(:context) { double 'context' }
|
5
5
|
let(:source) { '/resource/{id}' }
|
6
|
-
let(:pattern) { "http://test.host
|
6
|
+
let(:pattern) { "http://test.host#{source}" }
|
7
7
|
let(:relation) { described_class.new context, source, pattern }
|
8
8
|
subject { relation }
|
9
9
|
|
@@ -16,4 +16,24 @@ describe Restify::Relation do
|
|
16
16
|
expect(subject).to eq pattern
|
17
17
|
end
|
18
18
|
end
|
19
|
+
|
20
|
+
describe '#expand' do
|
21
|
+
let(:params) { {id: 1337} }
|
22
|
+
|
23
|
+
subject { relation.expand params }
|
24
|
+
|
25
|
+
it { is_expected.to be_a Addressable::URI }
|
26
|
+
|
27
|
+
context 'with #to_param object' do
|
28
|
+
class ParamObject
|
29
|
+
def to_param
|
30
|
+
42
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
let(:params) { {id: ParamObject.new} }
|
35
|
+
|
36
|
+
it { expect(subject.to_s).to eq 'http://test.host/resource/42' }
|
37
|
+
end
|
38
|
+
end
|
19
39
|
end
|