hyperresource 0.2.0 → 0.2.1

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: 8d9374b1ec64fdce21a54dfa34bd053c991f0541
4
- data.tar.gz: 0442f93a99aaed8e1e023ad9aa8ff00ecc2978f5
3
+ metadata.gz: fd19a34f267866e9a5086a1c9100cbb63f958ab5
4
+ data.tar.gz: 40856af8a0367f37c64e9e70996ef74f79b5424f
5
5
  SHA512:
6
- metadata.gz: c3e3388c09971d33a9c0062377ef356bcb35e2770c060d8d61ce0a8cf0a992b2f255726dbdaeffd94adee8ee91964eae2beff2e13551a3ac76a59d3a7e0add34
7
- data.tar.gz: 2eeb5c948b3736691cbf273310f4c98d8413ea2fa2a8725675985d9749bd035f42793828b1300e23452ac92fbf85b9a4de67153fec07f08790066a3cb577f4e9
6
+ metadata.gz: 01761608b3cddd8794bff9c8e58a918a4561c71cc39fe6f0946bd9cfa1a79cc2c54b1b828b57128c7a62f6382265301d567821aec14ea815546b4ba6edaa9ddd
7
+ data.tar.gz: 356516ad4974076570bb2031e46423a7d397949c80f2476140cdfce6c20a22a7f061ea849ff250b8b1afde649ad6c7f00ece3ea2e8d3714808c1956d3d5496be
@@ -1,22 +1,27 @@
1
1
  class HyperResource
2
+
3
+ ## HyperResource::Adapter is the interface/abstract base class for
4
+ ## adapters to different hypermedia formats (e.g., HAL+JSON). New
5
+ ## adapters must implement the public methods of this class.
6
+
2
7
  class Adapter
3
8
  class << self
4
9
 
5
- ## Serialize the object into a string.
10
+ ## Serialize the given object into a string.
6
11
  def serialize(object)
7
12
  raise NotImplementedError, "This is an abstract method -- subclasses "+
8
13
  "of HyperResource::Adapter must implement it."
9
14
  end
10
15
 
11
- ## Deserialize a string into an object.
16
+ ## Deserialize a given string into an object (Hash).
12
17
  def deserialize(string)
13
18
  raise NotImplementedError, "This is an abstract method -- subclasses "+
14
19
  "of HyperResource::Adapter must implement it."
15
20
  end
16
21
 
17
- ## Apply a response object (generally parsed JSON or XML) to the given
18
- ## HyperResource object. Returns the updated resource.
19
- def apply(object, resource, opts={})
22
+ ## Use a given deserialized response object (Hash) to update a given
23
+ ## resource (HyperResource), returning the updated resource.
24
+ def apply(response, resource, opts={})
20
25
  raise NotImplementedError, "This is an abstract method -- subclasses "+
21
26
  "of HyperResource::Adapter must implement it."
22
27
  end
@@ -68,12 +68,18 @@ class HyperResource
68
68
  links = rsrc.links
69
69
 
70
70
  resp['_links'].each do |rel, link_spec|
71
- if link_spec.is_a? Array
72
- links[rel] = link_spec.map do |link|
73
- new_link_from_spec(rsrc, link)
71
+ keys = [rel]
72
+ if m=rel.match(/.+:(.+)/)
73
+ keys << m[1]
74
+ end
75
+ keys.each do |key|
76
+ if link_spec.is_a? Array
77
+ links[key] = link_spec.map do |link|
78
+ new_link_from_spec(rsrc, link)
79
+ end
80
+ else
81
+ links[key] = new_link_from_spec(rsrc, link_spec)
74
82
  end
75
- else
76
- links[rel] = new_link_from_spec(rsrc, link_spec)
77
83
  end
78
84
  end
79
85
 
@@ -15,7 +15,6 @@ class HyperResource
15
15
 
16
16
  self.keys.each do |attr|
17
17
  attr_sym = attr.to_sym
18
-
19
18
  self.class.send(:define_method, attr_sym) do |*args|
20
19
  if args.count > 0
21
20
  self[attr].where(*args)
@@ -1,4 +1,4 @@
1
1
  class HyperResource
2
- VERSION = '0.2.0'
3
- VERSION_DATE = '2013-10-31'
2
+ VERSION = '0.2.1'
3
+ VERSION_DATE = '2013-11-10'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyperresource
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Gamache
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-31 00:00:00.000000000 Z
11
+ date: 2013-11-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uri_template