json_api_client 1.19.0 → 1.20.0
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/json_api_client/errors.rb +11 -0
- data/lib/json_api_client/resource.rb +15 -0
- data/lib/json_api_client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 399ea138115c4282afb7f24a8c6981533fc0e67d3e80078084002b8ab8cec5bd
|
4
|
+
data.tar.gz: aa737c7689874c8aef404b6aeabee2173b2294178486963928a2690495def95a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32657956fe3e7fc03e54d41c434a169613ee490684354cf1d59d864247743197de0858360a4d9e3f3003d073773563775bc8ca70a43be3948acb1c0557bd798c
|
7
|
+
data.tar.gz: 7aafe127cdc28013bf01e527c98b57f151004b49a5b9a482f12cd03ccce00b60e831c8aab80545651e4712ccb1a5f22bd04b157476503b01ab5ab20e4537750b
|
@@ -103,5 +103,16 @@ module JsonApiClient
|
|
103
103
|
super nil, msg
|
104
104
|
end
|
105
105
|
end
|
106
|
+
|
107
|
+
class RecordNotSaved < ServerError
|
108
|
+
attr_reader :record
|
109
|
+
|
110
|
+
def initialize(message = nil, record = nil)
|
111
|
+
@record = record
|
112
|
+
end
|
113
|
+
def message
|
114
|
+
"Record not saved"
|
115
|
+
end
|
116
|
+
end
|
106
117
|
end
|
107
118
|
end
|
@@ -172,6 +172,12 @@ module JsonApiClient
|
|
172
172
|
end
|
173
173
|
end
|
174
174
|
|
175
|
+
def create!(attributes = {})
|
176
|
+
new(attributes).tap do |resource|
|
177
|
+
raise(Errors::RecordNotSaved.new("Failed to save the record", resource)) unless resource.save
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
175
181
|
# Within the given block, add these headers to all requests made by
|
176
182
|
# the resource class
|
177
183
|
#
|
@@ -376,6 +382,11 @@ module JsonApiClient
|
|
376
382
|
save
|
377
383
|
end
|
378
384
|
|
385
|
+
def update_attributes!(attrs = {})
|
386
|
+
self.attributes = attrs
|
387
|
+
save ? true : raise(Errors::RecordNotSaved.new("Failed to update the record", self))
|
388
|
+
end
|
389
|
+
|
379
390
|
# Alias to update_attributes
|
380
391
|
#
|
381
392
|
# @param attrs [Hash] Attributes to update
|
@@ -384,6 +395,10 @@ module JsonApiClient
|
|
384
395
|
update_attributes(attrs)
|
385
396
|
end
|
386
397
|
|
398
|
+
def update!(attrs = {})
|
399
|
+
update_attributes!(attrs)
|
400
|
+
end
|
401
|
+
|
387
402
|
# Mark the record as persisted
|
388
403
|
def mark_as_persisted!
|
389
404
|
@persisted = true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: json_api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Ching
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-08
|
11
|
+
date: 2021-09-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|