yaqb 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/yaqb/hooks.rb +8 -3
- data/lib/yaqb/query_builders/paginators/pagy_helper.rb +45 -0
- data/lib/yaqb/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52b5538714ede2b23c96104bb339eddac611bfdf8562c648bb29094840c409e7
|
4
|
+
data.tar.gz: 78c09abab32cf2a75b1533cde2937d28dbea1bd86c9918fcd5b362bccf3eb29b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4a0aa3013b84a22f77b41e8b8d80a677cf96ded8e901635a8d683bc551d3c6b9a620a57e77e4c7df1b871b29046e4e2cb6b2dba2cb4ee82fc0fbf423f844d71
|
7
|
+
data.tar.gz: 7e1a4174fae0e07b22d5b601f57652fd8e2b0564af1422b7c488904b8c78c078a2ac44e3558f2177ed647a250fc31a4200c90a54e73cbe2b71e8080e21e29d83
|
data/Gemfile.lock
CHANGED
data/lib/yaqb/hooks.rb
CHANGED
@@ -2,13 +2,15 @@
|
|
2
2
|
|
3
3
|
begin; require 'kaminari'; rescue LoadError; end
|
4
4
|
begin; require 'will_paginate'; rescue LoadError; end
|
5
|
+
begin; require 'pagy'; rescue LoadError; end
|
5
6
|
|
6
|
-
unless defined?(Kaminari) || defined?(WillPaginate::CollectionMethods)
|
7
|
+
unless defined?(Kaminari) || defined?(WillPaginate::CollectionMethods) || defined?(Pagy)
|
7
8
|
Kernel.warn <<~HEREDOC
|
8
|
-
Warning: Yaqb relies on Kaminari or WillPaginate. Please
|
9
|
+
Warning: Yaqb relies on Kaminari or WillPaginate or Pagy. Please
|
9
10
|
install dependency by adding one of the following to your Gemfile:
|
10
11
|
gem 'kaminari'
|
11
|
-
gem 'will_paginate'
|
12
|
+
gem 'will_paginate'
|
13
|
+
gem 'pagy'\n
|
12
14
|
HEREDOC
|
13
15
|
end
|
14
16
|
|
@@ -19,6 +21,9 @@ begin
|
|
19
21
|
elsif defined?(WillPaginate::CollectionMethods)
|
20
22
|
require 'yaqb/query_builders/paginators/will_paginate_helper'
|
21
23
|
Yaqb::QueryBuilders::Paginate.send(:include, Yaqb::QueryBuilders::Paginators::WillPaginateHelper)
|
24
|
+
elsif defined?(Pagy)
|
25
|
+
require 'yaqb/query_builders/paginators/pagy_helper'
|
26
|
+
Yaqb::QueryBuilders::Paginate.send(:include, Yaqb::QueryBuilders::Paginators::PagyHelper)
|
22
27
|
else
|
23
28
|
raise LoadError
|
24
29
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yaqb
|
4
|
+
module QueryBuilders
|
5
|
+
module Paginators
|
6
|
+
module PagyHelper
|
7
|
+
private
|
8
|
+
|
9
|
+
def paginate!(scope)
|
10
|
+
@pagy = Pagy.new(count: scope.count(:all), page: @page, items: @per)
|
11
|
+
scope.offset(@pagy.offset).limit(@pagy.items)
|
12
|
+
end
|
13
|
+
|
14
|
+
def show_first_link?
|
15
|
+
@pagy.pages > 1 && !!@pagy.prev
|
16
|
+
end
|
17
|
+
|
18
|
+
def show_previous_link?
|
19
|
+
!!@pagy.prev
|
20
|
+
end
|
21
|
+
|
22
|
+
def show_next_link?
|
23
|
+
!!@pagy.next
|
24
|
+
end
|
25
|
+
|
26
|
+
def show_last_link?
|
27
|
+
@pagy.pages > 1 && !!@pagy.next
|
28
|
+
end
|
29
|
+
|
30
|
+
def pages
|
31
|
+
@pages ||= {}.tap do |h|
|
32
|
+
h[:first] = 1 if show_first_link?
|
33
|
+
h[:prev] = @pagy.prev if show_previous_link?
|
34
|
+
h[:next] = @pagy.next if show_next_link?
|
35
|
+
h[:last] = @pagy.pages if show_last_link?
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def default_per_page
|
40
|
+
Pagy::VARS[:items]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
data/lib/yaqb/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yaqb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ronald Chacon
|
@@ -93,6 +93,7 @@ files:
|
|
93
93
|
- lib/yaqb/query_builders/filter.rb
|
94
94
|
- lib/yaqb/query_builders/paginate.rb
|
95
95
|
- lib/yaqb/query_builders/paginators/kaminari_helper.rb
|
96
|
+
- lib/yaqb/query_builders/paginators/pagy_helper.rb
|
96
97
|
- lib/yaqb/query_builders/paginators/will_paginate_helper.rb
|
97
98
|
- lib/yaqb/query_builders/query_orchestrator.rb
|
98
99
|
- lib/yaqb/query_builders/sort.rb
|