Module: NoBrainer::Criteria::Index

Extended by:
ActiveSupport::Concern
Defined in:
lib/no_brainer/criteria/index.rb

Instance Method Summary collapse

Instance Method Details

#compile_rql_pass2Object



23
24
25
26
27
28
29
30
# File 'lib/no_brainer/criteria/index.rb', line 23

def compile_rql_pass2
  super.tap do
    # The implicit ordering on the indexed pk does not count.
    if @options[:use_index] && (!used_index || order_by_index_name.to_s == model.pk_name.to_s)
      raise NoBrainer::Error::CannotUseIndex.new(@options[:use_index])
    end
  end
end

#used_indexObject



18
19
20
21
# File 'lib/no_brainer/criteria/index.rb', line 18

def used_index
  # Only one of them will be active.
  where_index_name || order_by_index_name
end

#with_index(index_name = true) ⇒ Object



6
7
8
# File 'lib/no_brainer/criteria/index.rb', line 6

def with_index(index_name=true)
  chain(:use_index => index_name)
end

#without_indexObject



10
11
12
# File 'lib/no_brainer/criteria/index.rb', line 10

def without_index
  with_index(false)
end

#without_index?Boolean

Returns:



14
15
16
# File 'lib/no_brainer/criteria/index.rb', line 14

def without_index?
  finalized_criteria.options[:use_index] == false
end