Class: NoBrainer::Criteria::OrderBy::IndexFinder
- Inherits:
-
Struct
- Object
- Struct
- NoBrainer::Criteria::OrderBy::IndexFinder
- Defined in:
- lib/no_brainer/criteria/order_by.rb
Instance Method Summary collapse
- #could_find_index? ⇒ Boolean
- #find_index ⇒ Object
- #first_key ⇒ Object
- #first_key_indexable? ⇒ Boolean
Instance Method Details
#could_find_index? ⇒ Boolean
65 66 67 |
# File 'lib/no_brainer/criteria/order_by.rb', line 65 def could_find_index? !!self.index_name end |
#find_index ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/no_brainer/criteria/order_by.rb', line 79 def find_index return if criteria.without_index? return unless first_key_indexable? if criteria.[:use_index] && criteria.[:use_index] != true return unless first_key.to_s == criteria.[:use_index].to_s end # We need make sure that the where index finder has been invoked, it has priority. # If it doesn't find anything, we are free to go with our indexes. if !criteria.where_indexed? || (criteria.where_index_type == :between && first_key.to_s == criteria.where_index_name.to_s) self.index_name = first_key end end |
#first_key ⇒ Object
69 70 71 |
# File 'lib/no_brainer/criteria/order_by.rb', line 69 def first_key @first_key ||= criteria.__send__(:effective_order).to_a.first.try(:[], 0) end |
#first_key_indexable? ⇒ Boolean
73 74 75 76 77 |
# File 'lib/no_brainer/criteria/order_by.rb', line 73 def first_key_indexable? return false unless first_key.is_a?(Symbol) || first_key.is_a?(String) return false unless index = criteria.model.indexes[first_key.to_sym] return !index.multi && !index.geo end |