File: hooks.rb

package info (click to toggle)
ruby-api-pagination 4.8.2-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 272 kB
  • sloc: ruby: 1,125; makefile: 3
file content (43 lines) | stat: -rw-r--r-- 1,126 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
begin; require 'grape'; rescue LoadError; end
if defined?(Grape::API)
  require 'grape/pagination'

  klass = if Grape::VERSION >= '1.2.0' || defined?(Grape::API::Instance)
    Grape::API::Instance
  else
    Grape::API
  end

  klass.send(:include, Grape::Pagination)
end

begin; require 'pagy';          rescue LoadError; end
begin; require 'kaminari';      rescue LoadError; end
begin; require 'will_paginate'; rescue LoadError; end

unless defined?(Pagy) || defined?(Kaminari) || defined?(WillPaginate::CollectionMethods)
  Kernel.warn <<-WARNING.gsub(/^\s{4}/, '')
    Warning: api-pagination relies on either Pagy, Kaminari, or WillPaginate.
    Please install a paginator by adding one of the following to your Gemfile:

    gem 'pagy'
    gem 'kaminari'
    gem 'will_paginate'
  WARNING
end

if defined?(Rails)
  module ApiPagination
    module Hooks
      def self.rails_parent_controller
        if Rails::VERSION::MAJOR >= 5 || defined?(ActionController::API)
          ActionController::API
        else
          ActionController::Base
        end
      end
    end
  end

  require 'api-pagination/railtie'
end