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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17005bc88ac7813f9492d669c5eb8ffe2e8f80ca600455f4d563d6d06363f902
4
- data.tar.gz: 150b21556d5a33bea2d9b5d2b12999c5298cf4157bea34869b57324cab94416d
3
+ metadata.gz: c2f418d635feea4fc9b991da8be35ea33b733df916ef538651ed55abd9a8b2f1
4
+ data.tar.gz: 235060b6cb7f46e32b75dc2a9886dc7036e55793d13beb029a33546c01d6149e
5
5
  SHA512:
6
- metadata.gz: dffeb3fe0e26ea1984a119b19d5d6cd8b97c5c4179e9b02507e21882157f5f595ef71b16d39b977ece158a79fe9ea92b58f386cc71caa61104b6e5832740385a
7
- data.tar.gz: 2a794b74f9ffe077070b3485fe4eea40066a139eed7e2ce07ae97504df7a7ddb01154a02efdbe0509db6dc67f775b11aa72b477f8a7817bc8cb3cb5d1242d623
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?
@@ -32,6 +32,12 @@ module JsonApiClient
32
32
  class ClientError < ApiError
33
33
  end
34
34
 
35
+ class ResourceImmutableError < StandardError
36
+ def initialize(msg = 'Resource immutable')
37
+ super msg
38
+ end
39
+ end
40
+
35
41
  class AccessDenied < ClientError
36
42
  end
37
43
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module JsonApiClient
2
- VERSION = "1.15.0"
2
+ VERSION = "1.16.0"
3
3
  end
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.15.0
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-08-29 00:00:00.000000000 Z
11
+ date: 2019-09-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport