json_api_client 1.15.0 → 1.16.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/json_api_client/connection.rb +1 -0
- data/lib/json_api_client/errors.rb +6 -0
- data/lib/json_api_client/resource.rb +25 -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: c2f418d635feea4fc9b991da8be35ea33b733df916ef538651ed55abd9a8b2f1
|
4
|
+
data.tar.gz: 235060b6cb7f46e32b75dc2a9886dc7036e55793d13beb029a33546c01d6149e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d48e62663797fd41a0f00ff6e8261507db876a5cbbe0ba5f8bfff612114efc1557d1d77be32cb0f72af22769f9a7ed0880b8ba8dd5abb4d2ab258c349c1bd76d
|
7
|
+
data.tar.gz: 8291a372f23cc056a1745eec724c540b666c3e1b87b2f7777d787063c406caffe9e7efceab5dcdbda25c39e4817289fcd110cba1925ba81ad0401a36dff63098
|
@@ -14,6 +14,7 @@ module JsonApiClient
|
|
14
14
|
builder.use Middleware::JsonRequest
|
15
15
|
builder.use Middleware::Status, status_middleware_options
|
16
16
|
builder.use Middleware::ParseJson
|
17
|
+
builder.use ::FaradayMiddleware::Gzip
|
17
18
|
builder.adapter(*adapter_options)
|
18
19
|
end
|
19
20
|
yield(self) if block_given?
|
@@ -40,6 +40,11 @@ module JsonApiClient
|
|
40
40
|
instance_accessor: false
|
41
41
|
class_attribute :add_defaults_to_changes,
|
42
42
|
instance_writer: false
|
43
|
+
|
44
|
+
class_attribute :_immutable,
|
45
|
+
instance_writer: false,
|
46
|
+
default: false
|
47
|
+
|
43
48
|
self.primary_key = :id
|
44
49
|
self.parser = Parsers::Parser
|
45
50
|
self.paginator = Paginating::Paginator
|
@@ -94,6 +99,18 @@ module JsonApiClient
|
|
94
99
|
table_name
|
95
100
|
end
|
96
101
|
|
102
|
+
# Indicates whether this resource is mutable or immutable;
|
103
|
+
# by default, all resources are mutable.
|
104
|
+
#
|
105
|
+
# @return [Boolean]
|
106
|
+
def immutable(flag = true)
|
107
|
+
self._immutable = flag
|
108
|
+
end
|
109
|
+
|
110
|
+
def inherited(subclass)
|
111
|
+
subclass._immutable = false
|
112
|
+
end
|
113
|
+
|
97
114
|
# Specifies the relative path that should be used for this resource;
|
98
115
|
# by default, this is inferred from the resource class name.
|
99
116
|
#
|
@@ -215,6 +232,11 @@ module JsonApiClient
|
|
215
232
|
# @option [Symbol] :on One of [:collection or :member] to decide whether it's a collect or member method
|
216
233
|
# @option [Symbol] :request_method The request method (:get, :post, etc)
|
217
234
|
def custom_endpoint(name, options = {})
|
235
|
+
if _immutable
|
236
|
+
request_method = options.fetch(:request_method, :get).to_sym
|
237
|
+
raise JsonApiClient::Errors::ResourceImmutableError if request_method != :get
|
238
|
+
end
|
239
|
+
|
218
240
|
if :collection == options.delete(:on)
|
219
241
|
collection_endpoint(name, options)
|
220
242
|
else
|
@@ -440,6 +462,7 @@ module JsonApiClient
|
|
440
462
|
# @return [Boolean] Whether or not the save succeeded
|
441
463
|
def save
|
442
464
|
return false unless valid?
|
465
|
+
raise JsonApiClient::Errors::ResourceImmutableError if _immutable
|
443
466
|
|
444
467
|
self.last_result_set = if persisted?
|
445
468
|
self.class.requestor.update(self)
|
@@ -470,6 +493,8 @@ module JsonApiClient
|
|
470
493
|
#
|
471
494
|
# @return [Boolean] Whether or not the destroy succeeded
|
472
495
|
def destroy
|
496
|
+
raise JsonApiClient::Errors::ResourceImmutableError if _immutable
|
497
|
+
|
473
498
|
self.last_result_set = self.class.requestor.destroy(self)
|
474
499
|
if last_result_set.has_errors?
|
475
500
|
fill_errors
|
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.16.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: 2019-
|
11
|
+
date: 2019-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|