Class: Cursory::Mongoid

Inherits:
Base
  • Object
show all
Defined in:
lib/cursory/mongoid.rb

Constant Summary

Constants inherited from Base

Base::MAX_LIMIT

Instance Method Summary collapse

Methods inherited from Base

#clamped_limit, #clamped_offset, #count, #current_cursor, #cursor_clause, #cursor_clause_set, #cursor_data, #cursor_id, #cursor_object, #decompose_order_key, #initialize, #model_sort, #next_cursor, #order_keys, #page, #parsed_cursor, #record_for_next_cursor, #render_cursor, #search, #search_results, #sort_keys

Constructor Details

This class inherits a constructor from Cursory::Base

Instance Method Details

#clause_for_key(key, direction) ⇒ Object



39
40
41
# File 'lib/cursory/mongoid.rb', line 39

def clause_for_key key, direction
  { key.to_sym => { key_for_direction(direction) => cursor_object.send(key) } }
end

#constrained_searchObject



13
14
15
# File 'lib/cursory/mongoid.rb', line 13

def constrained_search
  criteria.order_by(order_clause).limit(clamped_limit)
end

#cursor_clausesObject



33
34
35
36
37
# File 'lib/cursory/mongoid.rb', line 33

def cursor_clauses
  if cursor_id
    { '$or' => cursor_clause_set.to_a }
  end
end

#key_for_direction(d) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/cursory/mongoid.rb', line 43

def key_for_direction(d)
  {
    'eq'   => '$eq',
    'asc'  => '$gt',
    'desc' => '$lt'
  }[d]
end

#modelObject



21
22
23
# File 'lib/cursory/mongoid.rb', line 21

def model
  criteria.klass
end

#order_clauseObject



29
30
31
# File 'lib/cursory/mongoid.rb', line 29

def order_clause
  order_keys.inject({}) { |hash, (key, value)| hash[key] = value; hash }
end

#search_typeObject



5
6
7
8
9
10
11
# File 'lib/cursory/mongoid.rb', line 5

def search_type
  if cursor
    [:where, cursor_clauses]
  else
    [:skip, clamped_offset]
  end
end

#uncached_countObject



17
18
19
# File 'lib/cursory/mongoid.rb', line 17

def uncached_count
  criteria.count
end

#uncached_cursor_objectObject



51
52
53
# File 'lib/cursory/mongoid.rb', line 51

def uncached_cursor_object
  criteria.klass.find(cursor_id)
end

#uncached_searchObject



25
26
27
# File 'lib/cursory/mongoid.rb', line 25

def uncached_search
  search.to_a
end