Module: Cash::Finders::ClassMethods
- Defined in:
- lib/cash/finders.rb
Class Method Summary collapse
Instance Method Summary collapse
- #_default_order ⇒ Object
- #_find_scope_with_default_order ⇒ Object
-
#calculate_with_cache(operation, column_name, options = {}) ⇒ Object
User.count(:all), User.count, User.sum(…).
- #find_by_id_with_exclusive_scope(id) ⇒ Object
-
#find_every_with_cache(options) ⇒ Object
User.find(:first, …), User.find_by_foo(…), User.find(:all, …), User.find_all_by_foo(…).
-
#find_from_ids_with_cache(ids, options) ⇒ Object
User.find(1), User.find(1, 2, 3), User.find([1, 2, 3]), User.find([]).
- #without_cache(&block) ⇒ Object
Class Method Details
.extended(active_record_class) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/cash/finders.rb', line 10 def self.extended(active_record_class) class << active_record_class alias_method_chain :find_every, :cache alias_method_chain :find_from_ids, :cache alias_method_chain :calculate, :cache end end |
Instance Method Details
#_default_order ⇒ Object
18 19 20 |
# File 'lib/cash/finders.rb', line 18 def _default_order @default_order ||= { :order => default_scope.first[:find][:order] || 'id ASC' } end |
#_find_scope_with_default_order ⇒ Object
22 23 24 25 |
# File 'lib/cash/finders.rb', line 22 def _find_scope_with_default_order find_scope = scope(:find) || {} find_scope[:order] ? find_scope : find_scope.merge(_default_order) end |
#calculate_with_cache(operation, column_name, options = {}) ⇒ Object
User.count(:all), User.count, User.sum(…)
48 49 50 |
# File 'lib/cash/finders.rb', line 48 def calculate_with_cache(operation, column_name, = {}) Query::Calculation.perform(self, operation, column_name, , _find_scope_with_default_order) end |
#find_by_id_with_exclusive_scope(id) ⇒ Object
27 28 29 30 31 |
# File 'lib/cash/finders.rb', line 27 def find_by_id_with_exclusive_scope(id) with_exclusive_scope({ :find => _default_order }) do find_from_ids_without_cache([id], {}) end end |
#find_every_with_cache(options) ⇒ Object
User.find(:first, …), User.find_by_foo(…), User.find(:all, …), User.find_all_by_foo(…)
38 39 40 |
# File 'lib/cash/finders.rb', line 38 def find_every_with_cache() Query::Select.perform(self, , _find_scope_with_default_order) end |
#find_from_ids_with_cache(ids, options) ⇒ Object
User.find(1), User.find(1, 2, 3), User.find([1, 2, 3]), User.find([])
43 44 45 |
# File 'lib/cash/finders.rb', line 43 def find_from_ids_with_cache(ids, ) Query::PrimaryKey.perform(self, ids, , _find_scope_with_default_order) end |
#without_cache(&block) ⇒ Object
33 34 35 |
# File 'lib/cash/finders.rb', line 33 def without_cache(&block) with_scope(:find => {:readonly => true}, &block) end |