seamusabshere-cache-money 0.2.8 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/cash/finders.rb CHANGED
@@ -24,11 +24,22 @@ module Cash
24
24
  find_scope[:order] ? find_scope : find_scope.merge(_default_order)
25
25
  end
26
26
 
27
- def find_by_id_with_exclusive_scope(id)
27
+ def _find_by_id_with_exclusive_scope(id)
28
28
  with_exclusive_scope({ :find => _default_order }) do
29
29
  find_from_ids_without_cache([id], {})
30
30
  end
31
31
  end
32
+
33
+ # http://github.com/entombedvirus/cache_fu/commit/78cf070aa281208dc63c58e58578afc04f9874c6
34
+ def _run_callbacks(result)
35
+ if result.respond_to?(:each)
36
+ result.each { |r| _run_callbacks(r) }
37
+ elsif result.is_a?(ActiveRecord::Base)
38
+ result.send(:callback, :after_initialize) if result.respond_to?(:after_initialize)
39
+ result.send(:callback, :after_find) if result.respond_to?(:after_find)
40
+ end
41
+ nil
42
+ end
32
43
 
33
44
  def without_cache(&block)
34
45
  with_scope(:find => {:readonly => true}, &block)
@@ -36,12 +47,16 @@ module Cash
36
47
 
37
48
  # User.find(:first, ...), User.find_by_foo(...), User.find(:all, ...), User.find_all_by_foo(...)
38
49
  def find_every_with_cache(options)
39
- Query::Select.perform(self, options, _find_scope_with_default_order)
50
+ results = Query::Select.perform(self, options, _find_scope_with_default_order)
51
+ _run_callbacks(results)
52
+ results
40
53
  end
41
54
 
42
55
  # User.find(1), User.find(1, 2, 3), User.find([1, 2, 3]), User.find([])
43
56
  def find_from_ids_with_cache(ids, options)
44
- Query::PrimaryKey.perform(self, ids, options, _find_scope_with_default_order)
57
+ results = Query::PrimaryKey.perform(self, ids, options, _find_scope_with_default_order)
58
+ _run_callbacks(results)
59
+ results
45
60
  end
46
61
 
47
62
  # User.count(:all), User.count, User.sum(...)
@@ -156,7 +156,7 @@ module Cash
156
156
 
157
157
  def find_from_keys(*missing_keys)
158
158
  missing_ids = Array(missing_keys).flatten.collect { |key| key.split('/')[2].to_i }
159
- missing_ids.map { |id| @active_record.find_by_id_with_exclusive_scope(id) }
159
+ missing_ids.map { |id| @active_record._find_by_id_with_exclusive_scope(id) }
160
160
  end
161
161
  end
162
162
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seamusabshere-cache-money
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Kallen