From d9bab83729752773b989fa5b3287bbe869198b81 Mon Sep 17 00:00:00 2001 From: Fotos Georgiadis Date: Fri, 7 Dec 2018 22:56:41 +0000 Subject: [PATCH] Add compatibility with Grape >= 1.2.0 --- lib/api-pagination/hooks.rb | 9 ++++++++- spec/grape_spec.rb | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/api-pagination/hooks.rb b/lib/api-pagination/hooks.rb index 89ea7dd..e6eb110 100644 --- a/lib/api-pagination/hooks.rb +++ b/lib/api-pagination/hooks.rb @@ -1,7 +1,14 @@ begin; require 'grape'; rescue LoadError; end if defined?(Grape::API) require 'grape/pagination' - Grape::API.send(:include, 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 diff --git a/spec/grape_spec.rb b/spec/grape_spec.rb index e42e1ef..168e864 100644 --- a/spec/grape_spec.rb +++ b/spec/grape_spec.rb @@ -5,6 +5,8 @@ require 'support/shared_examples/last_page' describe NumbersAPI do + it { is_expected.to be_kind_of(Grape::Pagination) } + describe 'GET #index' do let(:link) { last_response.headers['Link'] } let(:links) { link.split(', ') }