kasket 4.2.0 → 4.2.1

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: 70892c6d927d66172bfa651364fb0d83ab575b68
4
- data.tar.gz: 16fc178ed0ba3aee24b4547ab87337f5d28260bb
3
+ metadata.gz: e08086b85cd83c48b921c9ecc8ea4699831d1f96
4
+ data.tar.gz: 9aa1ba1f4777aaac0a9a7043aff17910448c3c0e
5
5
  SHA512:
6
- metadata.gz: 16844a7cdf3e9c8cdcd8612c33248372c3dcf30fde06607e06c9d021649e6a97810ab22bac1f8246f97015900b26992bf496fa5312c960e2988ea27d39358bbc
7
- data.tar.gz: 541bb732c0356a8425637619fb097699a130a003e71a8068c36c592e212763bc08db3ac1fdac7f31aec2b15702cc9b1901ab4356f60eec894589685c611c3eb8
6
+ metadata.gz: 2cfcbb81078feba7b513eb161d5c1a7f4a9144261360c4a33f4263163ee2ffabee35f7638dc374f7cdedcf78f9770441d5dad95f7b578363919e990ce8f63583
7
+ data.tar.gz: 05c0e405329c695da87f967b7d30b14834f3f543a7a6b8d04b9ca6fb8758e6eb30dbf0918a22b037a051e478484bfb86f230c44aea43f588eeb9ea20687f8ad3
@@ -39,4 +39,19 @@ module Kasket
39
39
  def self.cache
40
40
  @cache_store ||= Rails.cache
41
41
  end
42
+
43
+ # Keys are the records being saved.
44
+ # Values are either the saved record, or nil if the record has been destroyed.
45
+ def self.pending_records
46
+ Thread.current[:kasket_pending_records]
47
+ end
48
+
49
+ def self.add_pending_record(record, destroyed = false)
50
+ Thread.current[:kasket_pending_records] ||= {}
51
+ Thread.current[:kasket_pending_records][record] = destroyed ? nil : record
52
+ end
53
+
54
+ def self.clear_pending_records
55
+ Thread.current[:kasket_pending_records] = nil
56
+ end
42
57
  end
@@ -6,15 +6,15 @@ module Kasket
6
6
  module ConfigurationMixin
7
7
 
8
8
  def without_kasket(&block)
9
- old_value = Thread.current['kasket_disabled'] || false
10
- Thread.current['kasket_disabled'] = true
9
+ old_value = Thread.current[:kasket_disabled] || false
10
+ Thread.current[:kasket_disabled] = true
11
11
  yield
12
12
  ensure
13
- Thread.current['kasket_disabled'] = old_value
13
+ Thread.current[:kasket_disabled] = old_value
14
14
  end
15
15
 
16
16
  def use_kasket?
17
- !Thread.current['kasket_disabled']
17
+ !Thread.current[:kasket_disabled]
18
18
  end
19
19
 
20
20
  def kasket_parser
@@ -24,9 +24,9 @@ module Kasket
24
24
  else
25
25
  if value = Kasket.cache.read(query[:key])
26
26
  if value.is_a?(Array)
27
- find_by_sql_with_kasket_on_id_array(value)
27
+ filter_pending_records(find_by_sql_with_kasket_on_id_array(value))
28
28
  else
29
- Array.wrap(value).collect { |record| instantiate(record.dup) }
29
+ filter_pending_records(Array.wrap(value).collect { |record| instantiate(record.dup) })
30
30
  end
31
31
  else
32
32
  store_in_kasket(query[:key], find_by_sql_without_kasket(*args))
@@ -49,6 +49,14 @@ module Kasket
49
49
 
50
50
  protected
51
51
 
52
+ def filter_pending_records(records)
53
+ if pending_records = Kasket.pending_records
54
+ records.map { |record| pending_records.fetch(record, record) }.compact
55
+ else
56
+ records
57
+ end
58
+ end
59
+
52
60
  def missing_records_from_db(missing_keys)
53
61
  return {} if missing_keys.empty?
54
62
 
@@ -2,7 +2,7 @@ module Kasket
2
2
  class Version
3
3
  MAJOR = 4
4
4
  MINOR = 2
5
- PATCH = 0
5
+ PATCH = 1
6
6
  STRING = "#{MAJOR}.#{MINOR}.#{PATCH}"
7
7
  PROTOCOL = 4
8
8
  end
@@ -87,6 +87,29 @@ module Kasket
87
87
  clear_kasket_indices
88
88
  result
89
89
  end
90
+
91
+ def kasket_after_commit_dummy
92
+ # This is here to force committed! to be invoked.
93
+ end
94
+
95
+ def kasket_after_save
96
+ Kasket.add_pending_record(self)
97
+ end
98
+
99
+ def kasket_after_destroy
100
+ Kasket.add_pending_record(self, destroyed = true)
101
+ end
102
+
103
+ def committed!(*)
104
+ Kasket.clear_pending_records
105
+ kasket_after_commit if persisted? || destroyed?
106
+ super
107
+ end
108
+
109
+ def rolledback!(*)
110
+ Kasket.clear_pending_records
111
+ super
112
+ end
90
113
  end
91
114
 
92
115
  def self.included(model_class)
@@ -97,7 +120,9 @@ module Kasket
97
120
  model_class.send(:alias_method, :kasket_cacheable?, :default_kasket_cacheable?)
98
121
  end
99
122
 
100
- model_class.after_commit :kasket_after_commit
123
+ model_class.after_save :kasket_after_save
124
+ model_class.after_destroy :kasket_after_destroy
125
+ model_class.after_commit :kasket_after_commit_dummy
101
126
 
102
127
  if ActiveRecord::VERSION::MAJOR == 3 || (ActiveRecord::VERSION::MAJOR == 4 && ActiveRecord::VERSION::MINOR == 0)
103
128
  model_class.after_touch :kasket_after_commit
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kasket
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.2.0
4
+ version: 4.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mick Staugaard
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-01-02 00:00:00.000000000 Z
12
+ date: 2016-01-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord