hungry 0.1.3 → 0.1.4
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 +4 -4
- data/hungry.gemspec +1 -1
- data/lib/hungry/resource.rb +16 -16
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2b0770914fd6393e97e1e8cb8162e7be022884afcc2528b5a587d3da5cebe77d
|
4
|
+
data.tar.gz: 70250240e11cb07f0222edb3a24db4d303c9c0ed4c20a7d89e164e8523bc27a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81ff987d8812861e54c009cc822a6ce5edb2fa58991935b02ba3334f5d205d68906dd4cec42a58c2e44ed6583c6ace13e36ddeae39f010b9571e333d97227904
|
7
|
+
data.tar.gz: eb2d06c438f3b536d50a17920480e0f0c964a5b37337fe80ef7ee9818e97c81f140682b4ab14ffeccf5778dd7806b6f5867712a64dccfd45d596aacebdad49bf
|
data/hungry.gemspec
CHANGED
data/lib/hungry/resource.rb
CHANGED
@@ -14,17 +14,17 @@ module Hungry
|
|
14
14
|
super
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.belongs_to(
|
18
|
-
define_method
|
17
|
+
def self.belongs_to(association, klass = 'Resource')
|
18
|
+
define_method association do
|
19
19
|
@belongs_to ||= {}
|
20
|
-
@belongs_to[
|
20
|
+
@belongs_to[association] ||= begin
|
21
21
|
klass = Kernel.const_get(klass) if klass.is_a?(String)
|
22
22
|
|
23
|
-
if attributes[
|
24
|
-
resource = klass.new attributes[
|
23
|
+
if attributes[association].present?
|
24
|
+
resource = klass.new attributes[association]
|
25
25
|
resource.data_source = data_source
|
26
26
|
resource
|
27
|
-
elsif url = resources[
|
27
|
+
elsif url = resources[association]
|
28
28
|
attributes = self.class.get url
|
29
29
|
resource = klass.new attributes
|
30
30
|
resource.data_source = url
|
@@ -33,33 +33,33 @@ module Hungry
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
define_method "#{
|
36
|
+
define_method "#{association}=" do |object_or_attributes|
|
37
37
|
@belongs_to ||= {}
|
38
38
|
|
39
39
|
klass = Kernel.const_get(klass) if klass.is_a?(String)
|
40
40
|
|
41
41
|
if object_or_attributes.is_a?(klass)
|
42
|
-
@belongs_to[
|
42
|
+
@belongs_to[association] = object_or_attributes
|
43
43
|
elsif object_or_attributes.present?
|
44
|
-
|
44
|
+
self.attributes.merge!(association => object_or_attributes)
|
45
45
|
else
|
46
|
-
@belongs_to[
|
46
|
+
@belongs_to[association] = nil
|
47
47
|
end
|
48
48
|
|
49
|
-
@belongs_to[
|
49
|
+
@belongs_to[association]
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
def self.has_many(
|
54
|
-
define_method
|
53
|
+
def self.has_many(association, klass = 'Resource')
|
54
|
+
define_method association do
|
55
55
|
@has_many ||= {}
|
56
|
-
@has_many[
|
56
|
+
@has_many[association] ||= begin
|
57
57
|
klass = Kernel.const_get(klass) if klass.is_a?(String)
|
58
58
|
|
59
|
-
if url = resources[
|
59
|
+
if url = resources[association]
|
60
60
|
collection = klass.collection.from_url(url)
|
61
61
|
|
62
|
-
if attributes[
|
62
|
+
if attributes[association].present?
|
63
63
|
collection.results = attributes[resource]
|
64
64
|
end
|
65
65
|
|