hyperresource 0.2.2 → 0.2.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
  SHA1:
3
- metadata.gz: 0351125c7599e00df4a647dc4eb96b7633a0f76a
4
- data.tar.gz: 3c0e3dc94c9f4099bc7643d493bf5faeda0b3f38
3
+ metadata.gz: 832cf096d42bc62e2a0908b8a180daa50e74e995
4
+ data.tar.gz: 575f2ffc7974d107b48492e074a03cc614a0e587
5
5
  SHA512:
6
- metadata.gz: c9ee522c76596b6f0ef95f993e0e9897f5cea5d8348d093e2a9cdfdf8387e1bcde49a3b09d26a88909642511e2cd9b2110b05449480dc69748e97b071560f7c5
7
- data.tar.gz: 416e7d9cbdbf294bbcb47d4b8464674b47dd1f2844d9bb474eb656b27fe074b629d36bca382d9f9b8d452d4e777f172aadbdbfb62ad2a0cbe4441b4445109ccb
6
+ metadata.gz: 569688d842532fbb2676bf5058fdb259dbad3bec69cf751509bf32ea623853f0ad43c152b760a68d93a68e82b8f713795d3a561323295c67197fb055c78ad466
7
+ data.tar.gz: 41fc74dc8cab7d2100639c73849348086a55aab19b0d3b28d31660940df0418fe0406f2e713d4197f04c14f9896b81f0b323b8cfa254c9f5815c0464850f0c03
@@ -46,12 +46,16 @@ class HyperResource
46
46
 
47
47
  resp['_embedded'].each do |name, collection|
48
48
  if collection.is_a? Hash
49
- r = rc.new(:root => rsrc.root, :namespace => rsrc.namespace)
49
+ r = rc.new(:root => rsrc.root,
50
+ :headers => rsrc.headers,
51
+ :namespace => rsrc.namespace)
50
52
  r.body = collection
51
53
  objs[name] = apply(collection, r)
52
54
  else
53
55
  objs[name] = collection.map do |obj|
54
- r = rc.new(:root => rsrc.root, :namespace => rsrc.namespace)
56
+ r = rc.new(:root => rsrc.root,
57
+ :headers => rsrc.headers,
58
+ :namespace => rsrc.namespace)
55
59
  r.body = obj
56
60
  apply(obj, r)
57
61
  end
@@ -101,6 +105,7 @@ class HyperResource
101
105
  rsrc.attributes[attr] = filtered_attrs[attr]
102
106
  end
103
107
 
108
+ rsrc.attributes._hr_clear_changed
104
109
  rsrc.attributes._hr_create_methods!
105
110
  end
106
111
 
@@ -11,8 +11,10 @@ class HyperResource
11
11
  ## Protects against method creation into HyperResource::Attributes and
12
12
  ## HyperResource classes. Just subclasses, please!
13
13
  def _hr_create_methods!(opts={}) # @private
14
- return if self.class.to_s == 'HyperResource::Attributes' ||
15
- self._resource.class.to_s == 'HyperResource'
14
+ return if self.class.to_s == 'HyperResource::Attributes'
15
+ return if self._resource.class.to_s == 'HyperResource'
16
+ return if self.class.send(
17
+ :class_variable_defined?, :@@_hr_created_attributes_methods)
16
18
 
17
19
  self.keys.each do |attr|
18
20
  attr_sym = attr.to_sym
@@ -40,6 +42,8 @@ class HyperResource
40
42
 
41
43
  ## This is a good time to mark this object as not-changed
42
44
  _hr_clear_changed
45
+
46
+ self.class.send(:class_variable_set, :@@_hr_created_attributes_methods, true)
43
47
  end
44
48
 
45
49
  ## Returns +true+ if the given attribute has been changed since creation
@@ -59,7 +63,8 @@ class HyperResource
59
63
  end
60
64
 
61
65
  def []=(attr, value) # @private
62
- _hr_mark_changed(attr)
66
+ return self[attr] if self[attr] == value
67
+ _hr_mark_changed(attr)
63
68
  super(attr.to_s, value)
64
69
  end
65
70
 
@@ -70,11 +75,19 @@ class HyperResource
70
75
  end
71
76
 
72
77
  def method_missing(method, *args) # @private
73
- return self[method] if self[method]
74
- raise NoMethodError, "undefined method `#{method}' for #{self.inspect}"
78
+ method = method.to_s
79
+ if self[method]
80
+ self[method]
81
+ elsif method[-1,1] == '='
82
+ self[method[0..-2]] = args.first
83
+ else
84
+ raise NoMethodError, "undefined method `#{method}' for #{self.inspect}"
85
+ end
75
86
  end
76
87
 
77
- private
88
+ def _hr_clear_changed # @private
89
+ @_hr_changed = nil
90
+ end
78
91
 
79
92
  def _hr_mark_changed(attr, is_changed=true) # @private
80
93
  attr = attr.to_sym
@@ -82,10 +95,6 @@ class HyperResource
82
95
  @_hr_changed[attr] = is_changed
83
96
  end
84
97
 
85
- def _hr_clear_changed
86
- @_hr_changed = nil
87
- end
88
-
89
98
  end
90
99
  end
91
100
 
@@ -44,10 +44,12 @@ class HyperResource::Link
44
44
  parent_resource._hr_new_from_link(self.href)
45
45
  end
46
46
 
47
- ## Returns a HyperResource representing this link, and fetches it.
48
- def get
49
- self.resource.get
50
- end
47
+ ## Delegate HTTP methods to the resource.
48
+ def get(*args); self.resource.get(*args) end
49
+ def post(*args); self.resource.post(*args) end
50
+ def patch(*args); self.resource.patch(*args) end
51
+ def put(*args); self.resource.put(*args) end
52
+ def delete(*args); self.resource.delete(*args) end
51
53
 
52
54
  ## If we were called with a method we don't know, load this resource
53
55
  ## and pass the message along. This achieves implicit loading.
@@ -10,8 +10,10 @@ class HyperResource
10
10
  ## Protects against method creation into HyperResource::Links and
11
11
  ## HyperResource classes. Just subclasses, please!
12
12
  def _hr_create_methods!(opts={}) # @private
13
- return if self.class.to_s == 'HyperResource::Links' ||
14
- self._resource.class.to_s == 'HyperResource'
13
+ return if self.class.to_s == 'HyperResource::Links'
14
+ return if self._resource.class.to_s == 'HyperResource'
15
+ return if self.class.send(
16
+ :class_variable_defined?, :@@_hr_created_links_methods)
15
17
 
16
18
  self.keys.each do |attr|
17
19
  attr_sym = attr.to_sym
@@ -30,6 +32,8 @@ class HyperResource
30
32
  end
31
33
  end
32
34
  end
35
+
36
+ self.class.send(:class_variable_set, :@@_hr_created_links_methods, true)
33
37
  end
34
38
 
35
39
  def []=(attr, value) # @private
@@ -22,7 +22,8 @@ class HyperResource
22
22
 
23
23
  ## POSTs the given attributes to this resource's href, and returns
24
24
  ## the response resource.
25
- def post(attrs)
25
+ def post(attrs=nil)
26
+ attrs || self.attributes
26
27
  self.response = faraday_connection.post do |req|
27
28
  req.body = adapter.serialize(attrs)
28
29
  end
@@ -67,7 +68,13 @@ class HyperResource
67
68
  ## headers (including auth). Threadsafe.
68
69
  def faraday_connection(url=nil)
69
70
  url ||= URI.join(self.root, self.href)
70
- key = "faraday_connection_#{url}"
71
+ key = Digest::MD5.hexdigest({
72
+ 'faraday_connection' => {
73
+ 'url' => url,
74
+ 'headers' => self.headers,
75
+ 'ba' => self.auth[:basic]
76
+ }
77
+ }.to_json)
71
78
  return Thread.current[key] if Thread.current[key]
72
79
 
73
80
  fc = Faraday.new(self.faraday_options.merge(:url => url))
@@ -83,7 +90,7 @@ class HyperResource
83
90
 
84
91
  def finish_up
85
92
  begin
86
- self.body = self.adapter.deserialize(self.response.body)
93
+ self.body = self.adapter.deserialize(self.response.body) unless self.response.body.nil?
87
94
  rescue StandardError => e
88
95
  raise HyperResource::ResponseError.new(
89
96
  "Error when deserializing response body",
@@ -2,7 +2,7 @@ class HyperResource
2
2
  class Objects < Hash
3
3
  attr_accessor :_resource
4
4
 
5
- def initialize(resource=nil)
5
+ def initialize(resource=nil)
6
6
  self._resource = resource || HyperResource.new
7
7
  end
8
8
 
@@ -10,8 +10,10 @@ class HyperResource
10
10
  ## Protects against method creation into HyperResource::Objects and
11
11
  ## HyperResource classes. Just subclasses, please!
12
12
  def _hr_create_methods!(opts={}) # @private
13
- return if self.class.to_s == 'HyperResource::Objects' ||
14
- self._resource.class.to_s == 'HyperResource'
13
+ return if self.class.to_s == 'HyperResource::Objects'
14
+ return if self._resource.class.to_s == 'HyperResource'
15
+ return if self.class.send(
16
+ :class_variable_defined?, :@@_hr_created_objects_methods)
15
17
 
16
18
  self.keys.each do |attr|
17
19
  attr_sym = attr.to_sym
@@ -27,6 +29,8 @@ class HyperResource
27
29
  end
28
30
  end
29
31
  end
32
+
33
+ self.class.send(:class_variable_set, :@@_hr_created_objects_methods, true)
30
34
  end
31
35
 
32
36
  def []=(attr, value) # @private
@@ -1,4 +1,4 @@
1
1
  class HyperResource
2
- VERSION = '0.2.2'
3
- VERSION_DATE = '2014-02-21'
2
+ VERSION = '0.2.3'
3
+ VERSION_DATE = '2014-03-12'
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.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pete Gamache
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-21 00:00:00.000000000 Z
11
+ date: 2014-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: uri_template
@@ -108,20 +108,6 @@ dependencies:
108
108
  - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: 1.4.0
111
- - !ruby/object:Gem::Dependency
112
- name: yard
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - '>='
116
- - !ruby/object:Gem::Version
117
- version: 0.8.5
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - '>='
123
- - !ruby/object:Gem::Version
124
- version: 0.8.5
125
111
  description: |2
126
112
  HyperResource is a hypermedia client library for Ruby. Its goals are to
127
113
  interface directly with well-behaved hypermedia APIs, to allow the data
@@ -132,8 +118,9 @@ executables: []
132
118
  extensions: []
133
119
  extra_rdoc_files: []
134
120
  files:
135
- - lib/hyper_resource/adapter/hal_json.rb
121
+ - lib/hyper_resource.rb
136
122
  - lib/hyper_resource/adapter.rb
123
+ - lib/hyper_resource/adapter/hal_json.rb
137
124
  - lib/hyper_resource/attributes.rb
138
125
  - lib/hyper_resource/exceptions.rb
139
126
  - lib/hyper_resource/link.rb
@@ -143,7 +130,6 @@ files:
143
130
  - lib/hyper_resource/objects.rb
144
131
  - lib/hyper_resource/response.rb
145
132
  - lib/hyper_resource/version.rb
146
- - lib/hyper_resource.rb
147
133
  - lib/hyperresource.rb
148
134
  homepage: https://github.com/gamache/hyperresource
149
135
  licenses:
@@ -165,9 +151,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
165
151
  version: '0'
166
152
  requirements: []
167
153
  rubyforge_project:
168
- rubygems_version: 2.1.8
154
+ rubygems_version: 2.2.0
169
155
  signing_key:
170
156
  specification_version: 4
171
157
  summary: Extensible hypermedia client for Ruby
172
158
  test_files: []
173
- has_rdoc: true