hungry 0.1.2 → 0.1.3

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
  SHA256:
3
- metadata.gz: e23ebde7da2f1760c6504256a9520966ddb5b7cc6a1494bbe4764f590d0c4e28
4
- data.tar.gz: e0ba51bf6aa0ca1e3e678c5d47030c95742e9fbcedfea677a1ef565729d430a1
3
+ metadata.gz: 71b5da15b5d2419101d3ed190d9f87642f6454fce22b99e9a4981e8aad715ace
4
+ data.tar.gz: be1ccc4cb3bb30c6dccfd6af10a7627a185f5f07bdf5a7968a00034e1305b46d
5
5
  SHA512:
6
- metadata.gz: b0c46d06c571ab606b5a158dca21795cde6b858dad5c6847465977ae102b93f7fe232d8cd6227f2991c98d4233920fb6a2fddf08545b827a474bdac9e9c48001
7
- data.tar.gz: 9339bd32031272b9dcebad2d604071007005b6202f960ba7f17c5801aa8460b721bdf803e4d11762a31841d9619b05a35e1201dd25c928a8e9dc66e679432912
6
+ metadata.gz: 4b93430ac16e0d6bc0cee81bfdf9e71f15117044e4b00866fc78626c8240f167d5f743480f740b0cb3d1298aa5836d38e7b210cbf50ff50861cf527be626db14
7
+ data.tar.gz: 5ad076b163e208dd91fc1dc2c4d1e1cce38e7c75c554b83c50b936c489d1a09bad67e2594e6bd390e812eebe3cecbf87404af970d3505c02aae0113f5dbc7229
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hungry (0.1.1)
4
+ hungry (0.1.3)
5
5
  httparty
6
6
 
7
7
  GEM
@@ -40,17 +40,19 @@ GEM
40
40
  guard (~> 2.0)
41
41
  guard-compat (~> 1.0)
42
42
  spork (>= 0.8.4)
43
- httparty (0.13.7)
44
- json (~> 1.8)
43
+ httparty (0.17.3)
44
+ mime-types (~> 3.0)
45
45
  multi_xml (>= 0.5.2)
46
- json (1.8.3)
47
46
  listen (3.1.5)
48
47
  rb-fsevent (~> 0.9, >= 0.9.4)
49
48
  rb-inotify (~> 0.9, >= 0.9.7)
50
49
  ruby_dep (~> 1.2)
51
50
  lumberjack (1.0.10)
52
51
  method_source (0.8.2)
53
- multi_xml (0.5.5)
52
+ mime-types (3.3.1)
53
+ mime-types-data (~> 3.2015)
54
+ mime-types-data (3.2019.1009)
55
+ multi_xml (0.6.0)
54
56
  nenv (0.3.0)
55
57
  notiffany (0.1.0)
56
58
  nenv (~> 0.1)
@@ -101,4 +103,4 @@ DEPENDENCIES
101
103
  rspec
102
104
 
103
105
  BUNDLED WITH
104
- 1.12.5
106
+ 1.17.3
data/hungry.gemspec CHANGED
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  Gem::Specification.new do |s|
3
3
  s.name = 'hungry'
4
- s.version = '0.1.2'
4
+ s.version = '0.1.3'
5
5
  s.authors = ['Tom-Eric Gerritsen']
6
6
  s.email = ['tomeric@eet.nu']
7
7
  s.homepage = 'http://github.com/eet-nu/hungry'
@@ -2,15 +2,15 @@ module Hungry
2
2
  class Collection
3
3
  module Pagination
4
4
  class NotPaginatedError < StandardError; end
5
-
5
+
6
6
  def paginate(page, options = {})
7
7
  all options.merge(page: page)
8
8
  end
9
-
9
+
10
10
  def first(n = 1)
11
11
  scope = all(per_page: n, page: 1)
12
12
  results = scope.results
13
-
13
+
14
14
  if n == 1 && (value = results.first)
15
15
  resource = klass.new results.first
16
16
  resource.data_source = scope.data_source
@@ -23,11 +23,11 @@ module Hungry
23
23
  end
24
24
  end
25
25
  end
26
-
26
+
27
27
  def paginated?
28
28
  pagination.present?
29
29
  end
30
-
30
+
31
31
  def per_page
32
32
  if paginated?
33
33
  pagination['per_page'].to_i
@@ -35,7 +35,7 @@ module Hungry
35
35
  response['results'].length
36
36
  end
37
37
  end
38
-
38
+
39
39
  def total_entries
40
40
  if paginated?
41
41
  pagination['total_entries'].to_i
@@ -43,7 +43,7 @@ module Hungry
43
43
  response['results'].length
44
44
  end
45
45
  end
46
-
46
+
47
47
  def total_pages
48
48
  if paginated?
49
49
  pagination['total_pages'].to_i
@@ -51,7 +51,7 @@ module Hungry
51
51
  1
52
52
  end
53
53
  end
54
-
54
+
55
55
  def current_page
56
56
  if paginated?
57
57
  pagination['current_page'].to_i
@@ -59,27 +59,27 @@ module Hungry
59
59
  1
60
60
  end
61
61
  end
62
-
62
+
63
63
  def previous_page
64
64
  current_page - 1 if paginated? && current_page > 1
65
65
  end
66
-
66
+
67
67
  def next_page
68
68
  current_page + 1 if paginated? && current_page < total_pages
69
69
  end
70
-
70
+
71
71
  def previous
72
72
  raise NotPaginatedError unless paginated?
73
73
  all page: previous_page if previous_page
74
74
  end
75
-
75
+
76
76
  def next
77
77
  raise NotPaginatedError unless paginated?
78
78
  all page: next_page if next_page
79
79
  end
80
-
80
+
81
81
  private
82
-
82
+
83
83
  def pagination
84
84
  response['pagination']
85
85
  end
@@ -40,8 +40,10 @@ module Hungry
40
40
 
41
41
  if object_or_attributes.is_a?(klass)
42
42
  @belongs_to[resource] = object_or_attributes
43
- else
43
+ elsif object_or_attributes.present?
44
44
  @belongs_to[resource] = klass.new object_or_attributes
45
+ else
46
+ @belongs_to[resource] = nil
45
47
  end
46
48
 
47
49
  @belongs_to[resource]
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hungry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom-Eric Gerritsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-29 00:00:00.000000000 Z
11
+ date: 2020-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty