Class: Mincer::Processors::Pagination::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/mincer/processors/pagination/processor.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mincer) ⇒ Processor

Returns a new instance of Processor.



5
6
7
# File 'lib/mincer/processors/pagination/processor.rb', line 5

def initialize(mincer)
  @mincer, @args, @relation = mincer, mincer.args, mincer.relation
end

Class Method Details

.kaminari?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/mincer/processors/pagination/processor.rb', line 20

def self.kaminari?
  defined?(::Kaminari)
end

.will_paginate?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/mincer/processors/pagination/processor.rb', line 24

def self.will_paginate?
  defined?(::WillPaginate)
end

Instance Method Details

#applyObject



9
10
11
12
13
14
15
16
17
18
# File 'lib/mincer/processors/pagination/processor.rb', line 9

def apply
  if self.class.kaminari?
    @relation.page(page).per(per_page)
  elsif self.class.will_paginate?
    @relation.paginate(page: page, per_page: per_page)
  else
    warn 'To enable pagination please add kaminari or will_paginate to your Gemfile'
    @relation
  end
end

#pageObject



28
29
30
# File 'lib/mincer/processors/pagination/processor.rb', line 28

def page
  @args[::Mincer.config.pagination.page_param_name]
end

#per_pageObject



32
33
34
# File 'lib/mincer/processors/pagination/processor.rb', line 32

def per_page
  @mincer.class.default_per_page || @args[::Mincer.config.pagination.per_page_param_name]
end