hal-client 3.8.1 → 3.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3aa1556d1a5044c04bc66ad6b1e49105fbc124b7
4
- data.tar.gz: a266b7c77869e4f5b1429a4360ad3fa29d0de134
3
+ metadata.gz: 85cc05b22fd50911b4e49b91d2b8ee8512ee2fd3
4
+ data.tar.gz: cf83685b05bc87f970d868eedd93a035873768e9
5
5
  SHA512:
6
- metadata.gz: cd05cd62bdc95763d81d78e85c19042a8818ccafde1d4449d7ada687b1bde79d1f839a327c6162c42ced12a89fad171f0426d40f4fbe4206f8ae4f63cfe37a0f
7
- data.tar.gz: 755b04edb28982ba19f242355a69d9d2e7d7481744e80678641cbf37717ec2677a6cf690237926ed21a7d4e0cd7b88364016b5868092ba888755fc632f9faf00
6
+ metadata.gz: 2943114d371646828b0ec861ff157320791c55cc684941ebd1df90d3da6b1e68426c57cda34315a0b235f95930a7f5cc2a778513238703853570d4ef9a83691b
7
+ data.tar.gz: e8ca34954374194acdd19a952163a92aafc462719bda737be1b5a10019fb55b0db5cefb810615812c3fbe0568686c81699519610d44da4180398627ad5aa51b8
data/.travis.yml CHANGED
@@ -2,9 +2,8 @@ sudo: false
2
2
  cache: bundler
3
3
  language: ruby
4
4
  rvm:
5
- - "1.9.3"
6
5
  - "2.0.0"
7
6
  - "2.1.0"
8
7
  - "2.2.0"
9
- - jruby-19mode
10
- - jruby-21mode
8
+ - rbx-2.5.2
9
+
data/README.md CHANGED
@@ -128,7 +128,7 @@ doc.put(improved_doc) # save c
128
128
 
129
129
  ```
130
130
 
131
- This removes "John Plagerist" from the documents list of authors and then performs an HTTP PUT request with the updated document.
131
+ This removes the obsolete link to "John Doe" from the documents list of authors and replaces it with the correct link then performs an HTTP PUT request with the updated document.
132
132
 
133
133
  ### Custom media types
134
134
 
@@ -43,9 +43,14 @@ class HalClient
43
43
  # blk - When given only linked and embedded resource for whom
44
44
  # the block returns true will be rejected.
45
45
  #
46
+ # Options
47
+ #
48
+ # ignore - one or more categories of things to ignore. Valid
49
+ # values are: :broken_links. Default: []
50
+ #
46
51
  # Yields Representation of the target for each link/embedded.
47
- def reject_related(rel, &blk)
48
- reject_links(rel, &blk).reject_embedded(rel, &blk)
52
+ def reject_related(rel, ignore: [], &blk)
53
+ reject_links(rel, ignore: ignore, &blk).reject_embedded(rel, ignore: ignore, &blk)
49
54
  end
50
55
 
51
56
  # Returns a RepresentationEditor for a representation like the
@@ -55,13 +60,18 @@ class HalClient
55
60
  # blk - When given only links to resources for whom
56
61
  # the block returns true will be rejected.
57
62
  #
63
+ # Options
64
+ #
65
+ # ignore - one or more categories of things to ignore. Valid
66
+ # values are: :broken_links. Default: []
67
+ #
58
68
  # Yields Representation of the target for each link.
59
- def reject_links(rel, &blk)
69
+ def reject_links(rel, ignore: [], &blk)
60
70
  reject_from_section("_links",
61
71
  rel,
62
72
  ->(l) {Representation.new(href: l["href"],
63
73
  hal_client: hal_client)},
64
- blk)
74
+ ignoring(ignore, blk))
65
75
  end
66
76
 
67
77
  # Returns a RepresentationEditor for a representation like the
@@ -71,13 +81,18 @@ class HalClient
71
81
  # blk - When given only embedded resources for whom
72
82
  # the block returns true will be rejected.
73
83
  #
84
+ # Options
85
+ #
86
+ # ignore - one or more categories of things to ignore. Valid
87
+ # values are: :broken_links. Default: []
88
+ #
74
89
  # Yields Representation of the target for each embedded.
75
- def reject_embedded(rel, &blk)
90
+ def reject_embedded(rel, ignore: [], &blk)
76
91
  reject_from_section("_embedded",
77
92
  rel,
78
93
  ->(e) {Representation.new(parsed_json: e,
79
94
  hal_client: hal_client)},
80
- blk)
95
+ ignoring(ignore, blk))
81
96
  end
82
97
 
83
98
  # Returns a RepresentationEditor exactly like this one except that
@@ -143,5 +158,21 @@ class HalClient
143
158
 
144
159
  self.class.new(orig_repr, raw.merge(name => new_sec))
145
160
  end
161
+
162
+ def ignoring(criteria, filter)
163
+ Array(criteria)
164
+ .reduce(filter) {|f, c|
165
+ case c
166
+ when :broken_links
167
+ ->(*args) { begin
168
+ f.call(*args)
169
+ rescue HalClient::HttpClientError
170
+ false
171
+ end }
172
+ else
173
+ fail ArgumentError, "Unsupported ignore criteria: #{c}"
174
+ end
175
+ }
176
+ end
146
177
  end
147
178
  end
@@ -1,3 +1,3 @@
1
1
  class HalClient
2
- VERSION = "3.8.1"
2
+ VERSION = "3.9.0"
3
3
  end
@@ -26,6 +26,12 @@ RSpec.describe HalClient::RepresentationEditor do
26
26
  specify { expect(subject.reject_links("absent-rel")).to be_equivalent_json_to raw_hal }
27
27
  specify { expect(subject.reject_links("about") {|repr| %r|/another$| === repr.href })
28
28
  .not_to have_link "about" }
29
+
30
+ specify { expect{subject.reject_links("broken-link") {|repr| repr[:t] }}
31
+ .to raise_error HalClient::HttpClientError }
32
+ specify { expect{subject.reject_links("broken-link", ignore: :broken_links) { |repr|
33
+ repr[:t] }}
34
+ .not_to raise_error }
29
35
  end
30
36
 
31
37
  describe "#reject_embedded" do
@@ -74,12 +80,16 @@ RSpec.describe HalClient::RepresentationEditor do
74
80
 
75
81
  expect(altered).to have_link("replies", hash_including("value" => "-1"))
76
82
  .or(have_embedded("replies", hash_including("value" => "-1")))
77
-
78
83
  end
79
84
 
80
85
  specify { expect(subject.reject_related("absent-rel"))
81
86
  .to be_equivalent_json_to raw_hal }
82
87
 
88
+ specify { expect{subject.reject_related("broken-link") {|repr| repr[:t] }}
89
+ .to raise_error HalClient::HttpClientError }
90
+ specify { expect{subject.reject_related("broken-link", ignore: :broken_links) { |repr|
91
+ repr[:t] }}
92
+ .not_to raise_error }
83
93
  end
84
94
 
85
95
  describe "#set_property" do
@@ -116,8 +126,10 @@ RSpec.describe HalClient::RepresentationEditor do
116
126
 
117
127
  # Background
118
128
 
129
+ let(:hal_client) { HalClient.new }
119
130
  let(:a_repr) { HalClient::Representation
120
- .new(parsed_json: MultiJson.load(raw_hal)) }
131
+ .new(parsed_json: MultiJson.load(raw_hal),
132
+ hal_client: hal_client) }
121
133
 
122
134
  let(:raw_hal) { <<-HAL }
123
135
  { "age": 10
@@ -126,6 +138,7 @@ RSpec.describe HalClient::RepresentationEditor do
126
138
  ,"up" : [{ "href": "http://example.com/c1" },
127
139
  { "href": "http://example.com/c2" }]
128
140
  ,"about": { "href": "http://example.com/another" }
141
+ ,"broken-link": { "href": "http://example.com/missing" }
129
142
  }
130
143
  ,"_embedded": {
131
144
  "replies": [
@@ -136,6 +149,9 @@ RSpec.describe HalClient::RepresentationEditor do
136
149
  }
137
150
  HAL
138
151
 
152
+ let!(:missing_resource_req) { stub_request(:get, "http://example.com/missing")
153
+ .to_return(status: 404) }
154
+
139
155
  ANYTHING = ->(_) { true }
140
156
 
141
157
  matcher :be_templated do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hal-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.8.1
4
+ version: 3.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-22 00:00:00.000000000 Z
11
+ date: 2015-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http