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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/hungry.gemspec +1 -1
  3. data/lib/hungry/resource.rb +16 -16
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71b5da15b5d2419101d3ed190d9f87642f6454fce22b99e9a4981e8aad715ace
4
- data.tar.gz: be1ccc4cb3bb30c6dccfd6af10a7627a185f5f07bdf5a7968a00034e1305b46d
3
+ metadata.gz: 2b0770914fd6393e97e1e8cb8162e7be022884afcc2528b5a587d3da5cebe77d
4
+ data.tar.gz: 70250240e11cb07f0222edb3a24db4d303c9c0ed4c20a7d89e164e8523bc27a0
5
5
  SHA512:
6
- metadata.gz: 4b93430ac16e0d6bc0cee81bfdf9e71f15117044e4b00866fc78626c8240f167d5f743480f740b0cb3d1298aa5836d38e7b210cbf50ff50861cf527be626db14
7
- data.tar.gz: 5ad076b163e208dd91fc1dc2c4d1e1cce38e7c75c554b83c50b936c489d1a09bad67e2594e6bd390e812eebe3cecbf87404af970d3505c02aae0113f5dbc7229
6
+ metadata.gz: 81ff987d8812861e54c009cc822a6ce5edb2fa58991935b02ba3334f5d205d68906dd4cec42a58c2e44ed6583c6ace13e36ddeae39f010b9571e333d97227904
7
+ data.tar.gz: eb2d06c438f3b536d50a17920480e0f0c964a5b37337fe80ef7ee9818e97c81f140682b4ab14ffeccf5778dd7806b6f5867712a64dccfd45d596aacebdad49bf
@@ -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.3'
4
+ s.version = '0.1.4'
5
5
  s.authors = ['Tom-Eric Gerritsen']
6
6
  s.email = ['tomeric@eet.nu']
7
7
  s.homepage = 'http://github.com/eet-nu/hungry'
@@ -14,17 +14,17 @@ module Hungry
14
14
  super
15
15
  end
16
16
 
17
- def self.belongs_to(resource, klass = 'Resource')
18
- define_method resource do
17
+ def self.belongs_to(association, klass = 'Resource')
18
+ define_method association do
19
19
  @belongs_to ||= {}
20
- @belongs_to[resource] ||= begin
20
+ @belongs_to[association] ||= begin
21
21
  klass = Kernel.const_get(klass) if klass.is_a?(String)
22
22
 
23
- if attributes[resource].present?
24
- resource = klass.new attributes[resource]
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[resource]
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 "#{resource}=" do |object_or_attributes|
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[resource] = object_or_attributes
42
+ @belongs_to[association] = object_or_attributes
43
43
  elsif object_or_attributes.present?
44
- @belongs_to[resource] = klass.new object_or_attributes
44
+ self.attributes.merge!(association => object_or_attributes)
45
45
  else
46
- @belongs_to[resource] = nil
46
+ @belongs_to[association] = nil
47
47
  end
48
48
 
49
- @belongs_to[resource]
49
+ @belongs_to[association]
50
50
  end
51
51
  end
52
52
 
53
- def self.has_many(resource, klass = 'Resource')
54
- define_method resource do
53
+ def self.has_many(association, klass = 'Resource')
54
+ define_method association do
55
55
  @has_many ||= {}
56
- @has_many[resource] ||= begin
56
+ @has_many[association] ||= begin
57
57
  klass = Kernel.const_get(klass) if klass.is_a?(String)
58
58
 
59
- if url = resources[resource]
59
+ if url = resources[association]
60
60
  collection = klass.collection.from_url(url)
61
61
 
62
- if attributes[resource].present?
62
+ if attributes[association].present?
63
63
  collection.results = attributes[resource]
64
64
  end
65
65
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hungry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom-Eric Gerritsen