Module: DataMapper::Paginator

Defined in:
lib/dm-paginator/main.rb,
lib/dm-paginator/control.rb,
lib/dm-paginator/default.rb,
lib/dm-paginator/version.rb,
lib/dm-paginator/paginator.rb,
lib/dm-paginator/control/all.rb,
lib/dm-paginator/control/elastic.rb,
lib/dm-paginator/control/jumping.rb,
lib/dm-paginator/control/sliding.rb,
lib/dm-paginator/control/control_helper_abstract.rb

Defined Under Namespace

Modules: ControlHelper, ControlHelperAbstract Classes: Control, Main

Constant Summary collapse

VERSION =
"0.2.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#paginatorObject

Returns the value of attribute paginator.



3
4
5
# File 'lib/dm-paginator/paginator.rb', line 3

def paginator
  @paginator
end

Class Method Details

.defaultObject



10
11
12
# File 'lib/dm-paginator/default.rb', line 10

def self.default
  @default
end

Instance Method Details

#limit(options = {}) ⇒ Collection

Limit results.

Parameters:

  • options (Hash) (defaults to: {})

Returns:

  • (Collection)


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dm-paginator/paginator.rb', line 10

def limit options = {}
  # Remove this key if we come from limit_page method.
  page = options.delete :page
  query = options.dup
  collection = new_collection scoped_query( options = {
    :limit => options[:limit],
    :offset => options[:offset],
    :order => [options[:order]]
  }.merge( query ) )
  options.merge! :count => calculate_total_records( query ), :page => page
  collection.paginator = DataMapper::Paginator::Main.new options
  collection
end

#limit_page(page = nil, options = {}) ⇒ Collection

Limit results by page.

Parameters:

  • page (Integer, Hash) (defaults to: nil)
  • options (Hash) (defaults to: {})

Returns:

  • (Collection)


30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/dm-paginator/paginator.rb', line 30

def limit_page page = nil, options = {}
  if page.is_a?( Hash )
    options = page
  else
    options[:page] = page.to_i
  end

  options[:page] = options[:page].to_i > 0 ? options[:page] : DataMapper::Paginator.default[:page]
  options[:limit] = options[:limit].to_i || DataMapper::Paginator.default[:limit]
  options[:offset] = options[:limit] * ( options[:page] - 1 )
  options[:order] = options[:order] || DataMapper::Paginator.default[:order]
  limit options
end