yap 1.0.1 → 1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb8feec012229c542653414cb4cc9600dbd07fed
4
- data.tar.gz: 468697c601588f97ff517788dc8e874df9c1d730
3
+ metadata.gz: 977481c7c3322da6e497d1d853a316cfa58e8322
4
+ data.tar.gz: e5aee06760c0f49d79539c3f1105eb30625291d1
5
5
  SHA512:
6
- metadata.gz: cdfbeafd15a8e8e34df20875f7216f8af7b49a6e82cc86ad3808293bd18f1320479aaeeb8d288c6acabe1a7104542e2018b21925fac2742c652b7404ff3adcd8
7
- data.tar.gz: d98c220c7ff8a117b9b6c07de144cd0a0d74305fd46f107b703a1805fa33fa5a5d4b6e66b0aa84148c0ef8f23165b0e1a4f7ea3b97e1a09e6e82a3a3e633124b
6
+ metadata.gz: 34b7c4a7a2b88477e0bb1578c807f94fbf2743ce7c582d6d12eb48acdc1e6401954b66c92fa217982d014f902f61b648f3f365639a021f08d6a2fcbb217cfe68
7
+ data.tar.gz: 522e1d53ba3134c86ce946b743a91e7abd3529b69f98094755dc6d2e237625d9ed809d800d4307474c968e614b31403070b4b30486c65d115f9a6882226bdefa
data/README.md CHANGED
@@ -155,7 +155,12 @@ If an option cannot be parsed it will raise `Yap::PaginationError` or `Yap::Filt
155
155
 
156
156
  ## Changelog
157
157
 
158
- ### 1.0.0
158
+ ### 1.1
159
+
160
+ * changed default behavior for `range` to not include `total`; saves time when using `range`
161
+ * call `range(true)` to include total value
162
+
163
+ ### 1.0
159
164
 
160
165
  * changed `last_page` to base on the actual query not only the parameters
161
166
  * this now produces correct results if there are custom `where` conditions
@@ -35,20 +35,21 @@ module ActiveRecord
35
35
  end
36
36
 
37
37
  ##
38
- # Returns a hash defining a range with :from, :to and :total values.
38
+ # Returns a hash defining a range with :from, :to and optionally :total. Note that querying the total count requires
39
+ # an extra query to be executed.
39
40
  #
41
+ # @param [Boolean] include_total Include total value
40
42
  # @return [Hash] Values defining the range of the current page.
41
43
  #
42
- def range
44
+ def range(include_total = false)
43
45
  from = offset_value+1
44
46
  to = offset_value+limit_value
45
- to = total if total < to
47
+ to = total if total < to && include_total
46
48
 
47
- {
48
- from: from,
49
- to: to,
50
- total: total
51
- }
49
+ range = { from: from, to: to }
50
+ return range unless include_total
51
+
52
+ range.merge(total: total)
52
53
  end
53
54
  end
54
55
  end
data/lib/yap.rb CHANGED
@@ -40,7 +40,7 @@ module Yap
40
40
  ##
41
41
  # The paginate scope takes a hash as parameter. All options are optional and can be combined arbitrarily.
42
42
  #
43
- # @param [Hash] The parameters used for pagination (:page, :per_page, :sort, :direction)
43
+ # @param [Hash] params The parameters used for pagination (:page, :per_page, :sort, :direction)
44
44
  #
45
45
  scope :paginate, -> (params = {}) {
46
46
  page, per_page, order_by = extract_pagination_params(params)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Finn Glöe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-01 00:00:00.000000000 Z
11
+ date: 2015-04-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord