hal-client 2.2.1 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'forwardable'
|
2
1
|
require 'addressable/template'
|
3
2
|
|
4
3
|
require 'hal_client'
|
@@ -9,7 +8,6 @@ class HalClient
|
|
9
8
|
# HAL representation of a single resource. Provides access to
|
10
9
|
# properties, links and embedded representations.
|
11
10
|
class Representation
|
12
|
-
extend Forwardable
|
13
11
|
|
14
12
|
# Create a new Representation
|
15
13
|
#
|
@@ -38,6 +36,15 @@ class HalClient
|
|
38
36
|
@hal_client.post(href, data, options)
|
39
37
|
end
|
40
38
|
|
39
|
+
# Returns true if this representation contains the specified
|
40
|
+
# property.
|
41
|
+
#
|
42
|
+
# name - the name of the property to check
|
43
|
+
def property?(name)
|
44
|
+
raw.key? name
|
45
|
+
end
|
46
|
+
alias_method :has_property?, :property?
|
47
|
+
|
41
48
|
# Returns The value of the specified property or the specified
|
42
49
|
# default value.
|
43
50
|
#
|
@@ -96,13 +103,14 @@ class HalClient
|
|
96
103
|
# embedded links) whose rel is `link_rel`.
|
97
104
|
#
|
98
105
|
# link_rel - The link rel of interest
|
99
|
-
def
|
106
|
+
def related?(link_rel)
|
100
107
|
_ = related link_rel
|
101
108
|
true
|
102
109
|
|
103
110
|
rescue KeyError
|
104
111
|
false
|
105
112
|
end
|
113
|
+
alias_method :has_related?, :related?
|
106
114
|
|
107
115
|
# Returns representations of resources related via the specified
|
108
116
|
# link rel or the specified default value.
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'forwardable'
|
2
|
+
|
1
3
|
class HalClient
|
2
4
|
|
3
5
|
# A collection HAL representations
|
@@ -24,6 +26,7 @@ class HalClient
|
|
24
26
|
# Raises KeyError if the specified link does not exist
|
25
27
|
# and no default_proc is provided.
|
26
28
|
def related(link_rel, options={})
|
29
|
+
raise KeyError unless has_related? link_rel
|
27
30
|
RepresentationSet.new flat_map{|it| it.related(link_rel, options){[]}.to_a }
|
28
31
|
end
|
29
32
|
|
@@ -32,11 +35,7 @@ class HalClient
|
|
32
35
|
#
|
33
36
|
# link_rel - The link rel of interest
|
34
37
|
def has_related?(link_rel)
|
35
|
-
|
36
|
-
true
|
37
|
-
|
38
|
-
rescue KeyError
|
39
|
-
false
|
38
|
+
any? {|it| it.has_related?(link_rel) }
|
40
39
|
end
|
41
40
|
|
42
41
|
# Post a `Representation` or `String` to the resource.
|
data/lib/hal_client/version.rb
CHANGED
@@ -46,18 +46,14 @@ HAL
|
|
46
46
|
it { should eq "#<HalClient::Representation: http://example.com/foo>" }
|
47
47
|
end
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
49
|
+
specify { expect(repr.property "prop1").to eq 1 }
|
50
|
+
specify { expect{repr.property "nonexistent-prop"}.to raise_exception KeyError }
|
51
|
+
|
52
|
+
specify { expect(repr.property? "prop1").to be true }
|
53
|
+
specify { expect(repr.has_property? "prop1").to be true }
|
54
|
+
specify { expect(repr.property? "nonexistent-prop").to be false }
|
55
|
+
specify { expect(repr.has_property? "nonexistent-prop").to be false }
|
54
56
|
|
55
|
-
context "non-existent" do
|
56
|
-
it "raises exception" do
|
57
|
-
expect{repr.property 'wat'}.to raise_exception KeyError
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
57
|
|
62
58
|
its(:href) { should eq "http://example.com/foo" }
|
63
59
|
|
@@ -178,11 +174,14 @@ HAL
|
|
178
174
|
end
|
179
175
|
|
180
176
|
specify { expect(subject.has_related? "link1").to be true }
|
177
|
+
specify { expect(subject.related? "link1").to be true }
|
181
178
|
specify { expect(subject.has_related? "link3").to be true }
|
179
|
+
specify { expect(subject.related? "link3").to be true }
|
182
180
|
specify { expect(subject.has_related? "embed1").to be true }
|
181
|
+
specify { expect(subject.related? "embed1").to be true }
|
183
182
|
|
184
|
-
specify { expect(subject.has_related? "no-such-link").to be false }
|
185
|
-
specify { expect(subject.
|
183
|
+
specify { expect(subject.has_related? "no-such-link-or-embed").to be false }
|
184
|
+
specify { expect(subject.related? "no-such-link-or-embed").to be false }
|
186
185
|
|
187
186
|
context "curie links" do
|
188
187
|
let(:raw_repr) { <<-HAL }
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hal-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-03-
|
12
|
+
date: 2014-03-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -202,7 +202,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
202
202
|
version: '0'
|
203
203
|
segments:
|
204
204
|
- 0
|
205
|
-
hash: -
|
205
|
+
hash: -1374848680285234334
|
206
206
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
207
207
|
none: false
|
208
208
|
requirements:
|
@@ -211,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
211
211
|
version: '0'
|
212
212
|
segments:
|
213
213
|
- 0
|
214
|
-
hash: -
|
214
|
+
hash: -1374848680285234334
|
215
215
|
requirements: []
|
216
216
|
rubyforge_project:
|
217
217
|
rubygems_version: 1.8.23
|