Class: Cash::Query::Abstract
- Inherits:
-
Object
- Object
- Cash::Query::Abstract
- Defined in:
- lib/cash/query/abstract.rb
Direct Known Subclasses
Constant Summary collapse
- DESC =
/DESC/i
Class Method Summary collapse
Instance Method Summary collapse
- #calculation? ⇒ Boolean
-
#initialize(active_record, options1, options2) ⇒ Abstract
constructor
A new instance of Abstract.
- #limit ⇒ Object
- #offset ⇒ Object
- #order ⇒ Object
- #perform(find_options = {}, get_options = {}) ⇒ Object
Constructor Details
#initialize(active_record, options1, options2) ⇒ Abstract
Returns a new instance of Abstract.
10 11 12 |
# File 'lib/cash/query/abstract.rb', line 10 def initialize(active_record, , ) @active_record, @options1, @options2 = active_record, , || {} end |
Class Method Details
.perform(*args) ⇒ Object
6 7 8 |
# File 'lib/cash/query/abstract.rb', line 6 def self.perform(*args) new(*args).perform end |
Instance Method Details
#calculation? ⇒ Boolean
50 51 52 |
# File 'lib/cash/query/abstract.rb', line 50 def calculation? false end |
#limit ⇒ Object
42 43 44 |
# File 'lib/cash/query/abstract.rb', line 42 def limit @limit ||= @options1[:limit] || @options2[:limit] end |
#offset ⇒ Object
46 47 48 |
# File 'lib/cash/query/abstract.rb', line 46 def offset @offset ||= @options1[:offset] || @options2[:offset] || 0 end |
#order ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/cash/query/abstract.rb', line 31 def order @order ||= begin if order_sql = @options1[:order] || @options2[:order] matched, table_name, column_name, direction = *(ORDER.match(order_sql)) [column_name, direction =~ DESC ? :desc : :asc] else ['id', :asc] end end end |
#perform(find_options = {}, get_options = {}) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cash/query/abstract.rb', line 14 def perform( = {}, = {}) if cache_config = cacheable?(@options1, @options2, ) attribute_value_pairs, index = cache_config cache_keys = cache_keys(attribute_value_pairs) misses, missed_keys = nil, nil objects = get(cache_keys, .merge(:ttl => index.ttl)) do |missed_keys| misses = miss(missed_keys, @options1.merge(:limit => index.window)) serialize_objects(index, misses) end format_results(cache_keys, choose_deserialized_objects_if_possible(missed_keys, cache_keys, misses, objects)) else uncacheable end end |