json_api_client 1.6.3 → 1.6.4

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: 67a8db3df1fce550660b2b27fbbb30c304553ae3
4
- data.tar.gz: 24ec3342da42ecd76ef1e133fe9fa9cc140c24f3
3
+ metadata.gz: 43ad8115fe9360a602c120c6f4989ee54760d6a3
4
+ data.tar.gz: 9709b02b48e2c8b2295bd76b8620fcb1efaad487
5
5
  SHA512:
6
- metadata.gz: 30432af67345b35a56d056b00f200b7df6e3da1356f64e1f5182c1d9bc7221b9abf20c78763aea464b2480fb83c4fc688cf8b59634081a2755d980c9d599aacd
7
- data.tar.gz: 6feb1f54b43b9fc4c596fbbdc9e0ccb6baee06188ed0b61b9a7281c5653a51157d577598a07279c58080b59ecd9cf0d9d247463c48e524fb2b028de9f5ff78b0
6
+ metadata.gz: 0f7c487d82b18df80d0b7ca0a076028ea9b0b5b6eeb9e7a154f83a95d3a7f0af6af418418b06168dd860fd5c1225ec9a064603660354bfae3c42d7524d8bccb8
7
+ data.tar.gz: c4d8967b2a2e85a8c9ba486290e1f860551e83eab7e3022b3fc8d408ef2f3bd204ec56cd57e6e20c60cf72c6dfbddcf433281b4b45777fd00a6c49226080e6e9
data/README.md CHANGED
@@ -39,14 +39,29 @@ MyApi::Article.where(author_id: 1).all
39
39
  MyApi::Person.where(name: "foo").order(created_at: :desc).includes(:preferences, :cars).all
40
40
 
41
41
  u = MyApi::Person.new(first_name: "bar", last_name: "foo")
42
+ u.new_record?
43
+ # => true
42
44
  u.save
43
45
 
46
+ u.new_record?
47
+ # => false
48
+
44
49
  u = MyApi::Person.find(1).first
45
50
  u.update_attributes(
46
51
  a: "b",
47
52
  c: "d"
48
53
  )
49
54
 
55
+ u.persisted?
56
+ # => true
57
+
58
+ u.destroy
59
+
60
+ u.destroyed?
61
+ # => true
62
+ u.persisted?
63
+ # => false
64
+
50
65
  u = MyApi::Person.create(
51
66
  a: "b",
52
67
  c: "d"
@@ -315,6 +315,7 @@ module JsonApiClient
315
315
  def initialize(params = {})
316
316
  params = params.symbolize_keys
317
317
  @persisted = nil
318
+ @destroyed = nil
318
319
  self.links = self.class.linker.new(params.delete(:links) || {})
319
320
  self.relationships = self.class.relationship_linker.new(self.class, params.delete(:relationships) || {})
320
321
  self.attributes = self.class.default_attributes.merge(params)
@@ -355,14 +356,26 @@ module JsonApiClient
355
356
  #
356
357
  # @return [Boolean]
357
358
  def persisted?
358
- !!@persisted && has_attribute?(self.class.primary_key)
359
+ !!@persisted && !destroyed? && has_attribute?(self.class.primary_key)
360
+ end
361
+
362
+ # Mark the record as destroyed
363
+ def mark_as_destroyed!
364
+ @destroyed = true
365
+ end
366
+
367
+ # Whether or not this record has been destroyed to the database previously
368
+ #
369
+ # @return [Boolean]
370
+ def destroyed?
371
+ !!@destroyed
359
372
  end
360
373
 
361
374
  # Returns true if this is a new record (never persisted to the database)
362
375
  #
363
376
  # @return [Boolean]
364
377
  def new_record?
365
- !persisted?
378
+ !persisted? && !destroyed?
366
379
  end
367
380
 
368
381
  # When we represent this resource as a relationship, we do so with id & type
@@ -449,8 +462,7 @@ module JsonApiClient
449
462
  fill_errors
450
463
  false
451
464
  else
452
- self.attributes.clear
453
- self.relationships.attributes.clear
465
+ mark_as_destroyed!
454
466
  self.relationships.last_result_set = nil
455
467
  _clear_cached_relationships
456
468
  true
@@ -1,3 +1,3 @@
1
1
  module JsonApiClient
2
- VERSION = "1.6.3"
2
+ VERSION = "1.6.4"
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.6.3
4
+ version: 1.6.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Ching
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-12 00:00:00.000000000 Z
11
+ date: 2018-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport