Class: Munson::Paginator::OffsetPaginator

Inherits:
Object
  • Object
show all
Defined in:
lib/munson/paginator/offset_paginator.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ OffsetPaginator

Returns a new instance of OffsetPaginator.



4
5
6
7
# File 'lib/munson/paginator/offset_paginator.rb', line 4

def initialize(options={})
  @max_limit = options[:max]
  @default_limit = options[:default]
end

Instance Method Details

#set(opts = {}) ⇒ Object



9
10
11
12
# File 'lib/munson/paginator/offset_paginator.rb', line 9

def set(opts={})
  limit(opts[:limit]) if opts[:limit]
  offset(opts[:offset]) if opts[:offset]
end

#to_paramsObject



14
15
16
17
18
19
20
21
# File 'lib/munson/paginator/offset_paginator.rb', line 14

def to_params
  {
    page: {
      limit: @limit || @default_limit || 10,
      offset: @offset
    }.select { |_, value| !value.nil? }
  }
end