Module: WillPaginate::DataMapper::CollectionMethods

Includes:
CollectionMethods
Defined in:
lib/will_paginate/data_mapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CollectionMethods

#next_page, #out_of_bounds?, #previous_page, #total_pages

Instance Attribute Details

#current_pageObject

Returns the value of attribute current_page.



39
40
41
# File 'lib/will_paginate/data_mapper.rb', line 39

def current_page
  @current_page
end

#total_entriesObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/will_paginate/data_mapper.rb', line 54

def total_entries
  @total_entries ||= begin
    if loaded? and @array.size < per_page and (current_page == 1 or @array.size > 0)
      offset + @array.size
    else
      # :reload prevents Collection.filter from being run, which
      # would cause a stack overflow
      clean_query = query.merge(:reload => true)
      # seems like the only way
      clean_query.instance_variable_set('@limit', nil)
      clean_query.instance_variable_set('@offset', 0)
      new_collection(clean_query).count
    end
  end
end

Instance Method Details

#offsetObject



50
51
52
# File 'lib/will_paginate/data_mapper.rb', line 50

def offset
  query.offset
end

#paginated?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/will_paginate/data_mapper.rb', line 42

def paginated?
  !current_page.nil?
end

#per_pageObject



46
47
48
# File 'lib/will_paginate/data_mapper.rb', line 46

def per_page
  query.limit || model.per_page
end

#to_aObject



70
71
72
73
74
75
76
77
78
79
# File 'lib/will_paginate/data_mapper.rb', line 70

def to_a
  if paginated?
    ::WillPaginate::Collection.create(current_page, per_page) do |col|
      col.replace super
      col.total_entries ||= total_entries
    end
  else
    super
  end
end