productive 0.5.3 → 0.5.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 77f29b8aec3d5246bfa8c47324367f71a8d89fe1
4
- data.tar.gz: 164de5a9592b69346d43d62afd5810722f7e2275
3
+ metadata.gz: 135076a9825c5ba98a32ae6adcf847bee2613d14
4
+ data.tar.gz: 2926f11187cd278ca1d6b6c481e8df905ca44988
5
5
  SHA512:
6
- metadata.gz: 1cfbcdea8b7ed820c83c954b23b482fc9c9fbfc4909fc4818c8c505af790c826b34c9f1f13d6f9ae56b903dba771163bae7c8592ff821dcfadd44bda626b5b10
7
- data.tar.gz: 7cff7c8493628f0d22f9919e9448328a33d0d9c9e25ac4125352e534e2acd048da64d6e7e9a7750090785522551a80392dcb48ef8abcfa25d1ae89f6f6e3cde1
6
+ metadata.gz: 69c10baf363ebb19915aaac3b81bce0f3404bb7e30092c552ed1f61587205e3e35098d887c09f64fc64145a1486c43ab8de9ce27a2493c94e32a7678adcd46ed
7
+ data.tar.gz: 1281601acbc2c4648ca60a7330435855561dccdf9da4092adcc9e728ecf0408aa5d0e3d6d340712f43a96f9f7957dd752e46e001a8a066e3a5cfc4e0e1bb5d44
@@ -21,30 +21,44 @@ module Productive
21
21
  end
22
22
 
23
23
  def self.all(args = {})
24
- arr = []
25
- page = 1
24
+ depaginate(BaseItems.new([]), args).items
25
+ end
26
+
27
+ def self.lazy_all(args = {})
28
+ Enumerator.new do |yielder|
29
+ depaginate(LazyItems.new(yielder), args)
30
+ end.lazy
31
+ end
32
+
33
+ def self.depaginate(items, args)
34
+ page = paginate(per_page: PER_PAGE).find(args)
35
+ items.append(page)
26
36
 
27
37
  loop do
28
- results = paginate(per_page: PER_PAGE, page: page).find(args)
29
- raise StopIteration if results.empty?
30
- arr += results
31
- page += 1
38
+ page = page.pages.next
39
+ raise StopIteration if page.nil?
40
+ items.append(page)
32
41
  end
33
42
 
34
- arr
43
+ items
35
44
  end
36
45
 
37
- def self.lazy_all
38
- Enumerator.new do |yielder|
39
- page = 1
40
-
41
- loop do
42
- results = paginate(per_page: PER_PAGE, page: page).find(args)
43
- raise StopIteration if results.empty?
44
- results.each { |item| yielder << item }
45
- page += 1
46
- end
47
- end.lazy
46
+ class BaseItems
47
+ attr_reader :items
48
+
49
+ def initialize(items)
50
+ @items = items
51
+ end
52
+
53
+ def append(results)
54
+ @items += results
55
+ end
56
+ end
57
+
58
+ class LazyItems < BaseItems
59
+ def append(results)
60
+ results.each { |item| @items << item }
61
+ end
48
62
  end
49
63
  end
50
64
  end
@@ -1,3 +1,3 @@
1
1
  module Productive
2
- VERSION = '0.5.3'.freeze
2
+ VERSION = '0.5.4'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: productive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.3
4
+ version: 0.5.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josip Bišćan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-10 00:00:00.000000000 Z
11
+ date: 2017-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack