deep_unrest 0.1.29 → 0.1.30

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: c3db9b5260b0790867e3dbac37d5c4010450ee89
4
- data.tar.gz: 6ba9b159d08d7ec3ef9e854c26f8232145c6cc9e
3
+ metadata.gz: 3395eda13825d0ecdfe337b515741edc5b5e25a6
4
+ data.tar.gz: 0fec2b4c1003af2d6ed883fc1d0398bd457eb875
5
5
  SHA512:
6
- metadata.gz: 13d2bf8a5aad60df45696fbd373afa0affd786e8cdaaa6130b06222d701738002878fc61045cf4b05dcafeacc1d14346a550a3e649e656719fd9ed64300f99cb
7
- data.tar.gz: b6c630391bc3f5bf86b95e9ae9d154c77071882778a444ed7cc07c9480dfb1d47160e04cdca10c8b61689374428cfb747072184bce65ae92da90d015119a4cfd
6
+ metadata.gz: 441ebd1c53d3717286b4b30ef2ac201f5470d3d9f718a5757e3dae79b4152c1232b7c1d919f0ea9b554272137eea75c7d5454a7fc1dd2c01db355415c184f318
7
+ data.tar.gz: 8b4066e6233a7dd6922e5e9aa55bd2f753d9ceae53714b31b0c3fcf87c1087cc26e95d787d52ced89e3be1c86622fee7ee0304d4c157c8fc4c6c1051b36ba1b4
@@ -5,6 +5,7 @@ module DeepUnrest
5
5
  include DeepUnrest.authentication_concern
6
6
 
7
7
  @@temp_ids = {}
8
+ @@destroyed_entities = []
8
9
 
9
10
  def context
10
11
  { current_user: current_user }
data/lib/deep_unrest.rb CHANGED
@@ -250,7 +250,6 @@ module DeepUnrest
250
250
  case action
251
251
  when :destroy
252
252
  cursor[:_destroy] = true
253
- scope[:destroyed] = true
254
253
  when :update, :create, :update_all
255
254
  cursor.merge! parse_attributes(type,
256
255
  operation[:action],
@@ -543,15 +542,13 @@ module DeepUnrest
543
542
  .compact
544
543
 
545
544
  if errors.empty?
545
+ destroyed = DeepUnrest::ApplicationController.class_variable_get(
546
+ '@@destroyed_entities'
547
+ )
546
548
  return {
547
549
  redirect_regex: build_redirect_regex(temp_id_map[ctx]),
548
550
  temp_ids: temp_id_map[ctx],
549
- destroyed: scopes.select { |item| item[:destroyed] }
550
- .map do |item|
551
- { type: item[:type],
552
- id: parse_id(item[:id]),
553
- destroyed: true }
554
- end
551
+ destroyed: destroyed
555
552
  }
556
553
  end
557
554
 
@@ -7,16 +7,30 @@ module DeepUnrest
7
7
  attr_accessor :deep_unrest_context
8
8
  attr_accessor :deep_unrest_temp_id
9
9
  after_create :map_temp_id
10
+ after_destroy :track_destruction
10
11
  end
11
12
 
12
13
  def map_temp_id
13
- # return unless @deep_unrest_temp_id
14
14
  temp_id_map = DeepUnrest::ApplicationController.class_variable_get(
15
15
  '@@temp_ids'
16
16
  )
17
17
  return unless temp_id_map && @deep_unrest_temp_id
18
18
  temp_id_map[@deep_unrest_context][@deep_unrest_temp_id] = id
19
19
  end
20
+
21
+ # the client needs to know which items were destroyed so it can clean up
22
+ # the dead entities from its local store
23
+ def track_destruction
24
+ destroyed = DeepUnrest::ApplicationController.class_variable_get(
25
+ '@@destroyed_entities'
26
+ )
27
+ return unless destroyed
28
+ destroyed << {
29
+ type: self.class.to_s.pluralize.camelize(:lower),
30
+ id: id,
31
+ destroyed: true
32
+ }
33
+ end
20
34
  end
21
35
  end
22
36
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module DeepUnrest
4
- VERSION = '0.1.29'
4
+ VERSION = '0.1.30'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: deep_unrest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.29
4
+ version: 0.1.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lynn Hurley
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-09-17 00:00:00.000000000 Z
11
+ date: 2018-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails