Class: MongoidExt::Filter::ResultSet

Inherits:
Object
  • Object
show all
Defined in:
lib/mongoid_ext/filter/result_set.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(total_entries, parsed_query, mongo_query, current_page, per_page = nil) ⇒ ResultSet

Returns a new instance of ResultSet.



15
16
17
18
19
20
21
# File 'lib/mongoid_ext/filter/result_set.rb', line 15

def initialize(total_entries, parsed_query, mongo_query, current_page, per_page=nil)
  @total_entries    = total_entries.to_i
  @mongo_query = mongo_query
  @parsed_query = parsed_query
  self.per_page     = per_page
  self.current_page = current_page
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



57
58
59
# File 'lib/mongoid_ext/filter/result_set.rb', line 57

def method_missing(name, *args, &block)
  @subject.send(name, *args, &block)
end

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



8
9
10
# File 'lib/mongoid_ext/filter/result_set.rb', line 8

def current_page
  @current_page
end

#mongo_queryObject (readonly)

Returns the value of attribute mongo_query.



10
11
12
# File 'lib/mongoid_ext/filter/result_set.rb', line 10

def mongo_query
  @mongo_query
end

#parsed_queryObject (readonly)

Returns the value of attribute parsed_query.



9
10
11
# File 'lib/mongoid_ext/filter/result_set.rb', line 9

def parsed_query
  @parsed_query
end

#per_pageObject Also known as: limit, limit_value

Returns the value of attribute per_page.



8
9
10
# File 'lib/mongoid_ext/filter/result_set.rb', line 8

def per_page
  @per_page
end

#subjectObject

Returns the value of attribute subject.



7
8
9
# File 'lib/mongoid_ext/filter/result_set.rb', line 7

def subject
  @subject
end

#total_entriesObject (readonly) Also known as: total_count

Returns the value of attribute total_entries.



8
9
10
# File 'lib/mongoid_ext/filter/result_set.rb', line 8

def total_entries
  @total_entries
end

Instance Method Details

#===(other) ⇒ Object



53
54
55
# File 'lib/mongoid_ext/filter/result_set.rb', line 53

def ===(other)
  other === subject
end

#next_pageObject



36
37
38
# File 'lib/mongoid_ext/filter/result_set.rb', line 36

def next_page
  current_page < total_pages ? (current_page + 1) : nil
end

#out_of_bounds?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/mongoid_ext/filter/result_set.rb', line 28

def out_of_bounds?
  current_page > total_pages
end

#previous_pageObject



32
33
34
# File 'lib/mongoid_ext/filter/result_set.rb', line 32

def previous_page
  current_page > 1 ? (current_page - 1) : nil
end

#respond_to?(name, *args, &block) ⇒ Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/mongoid_ext/filter/result_set.rb', line 61

def respond_to?(name, *args, &block)
  super || @subject.respond_to?(name, *args, &block)
end

#send(method, *args, &block) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/mongoid_ext/filter/result_set.rb', line 45

def send(method, *args, &block)
  if respond_to?(method)
    super
  else
    subject.send(method, *args, &block)
  end
end

#skipObject Also known as: offset



40
41
42
# File 'lib/mongoid_ext/filter/result_set.rb', line 40

def skip
  (current_page - 1) * per_page
end

#total_pagesObject Also known as: num_pages



23
24
25
# File 'lib/mongoid_ext/filter/result_set.rb', line 23

def total_pages
  (total_entries / per_page.to_f).ceil
end