activeresource 6.0.0 → 6.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/active_resource/base.rb +7 -7
- data/lib/active_resource/connection.rb +1 -1
- data/lib/active_resource/custom_methods.rb +1 -1
- data/lib/active_resource/http_mock.rb +26 -11
- data/lib/active_resource/inheriting_hash.rb +19 -0
- data/lib/active_resource/validations.rb +1 -1
- data/lib/active_resource/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb092fb2d853c88525dc4f656733f5ba9c4865d1092ee376f598c1ec944c0e02
|
4
|
+
data.tar.gz: c907a425824ed9227dbc9b48195bf38c0ffb9d6312ab13a63270b973450482b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b287742d4867cef996a87ce8a0ef285eb2012cfa23f9c47cf149f9086ea4df620fa945952a24e160bc07201601672702edb43bd4d6279a95a58734118d9c457f
|
7
|
+
data.tar.gz: b9a74b86bcc934044ebf06df35b0a48729fdba4947785583c2c403901729b6d7133657e4131db13b8d3229502896afa8db7ef0ac87aa5c6762dafbcb1b0a326a
|
data/README.md
CHANGED
@@ -112,7 +112,7 @@ end
|
|
112
112
|
Active Resource is built on a standard JSON or XML format for requesting and submitting resources
|
113
113
|
over HTTP. It mirrors the RESTful routing built into Action Controller but will also work with any
|
114
114
|
other REST service that properly implements the protocol. REST uses HTTP, but unlike "typical" web
|
115
|
-
applications, it makes use of all the
|
115
|
+
applications, it makes use of all the verbs available in the HTTP specification:
|
116
116
|
|
117
117
|
* GET requests are used for finding and retrieving resources.
|
118
118
|
* POST requests are used to create new resources.
|
data/lib/active_resource/base.rb
CHANGED
@@ -1072,13 +1072,13 @@ module ActiveResource
|
|
1072
1072
|
#
|
1073
1073
|
# Note.exists(1349) # => false
|
1074
1074
|
def exists?(id, options = {})
|
1075
|
-
|
1076
|
-
|
1077
|
-
|
1078
|
-
|
1079
|
-
|
1080
|
-
|
1081
|
-
|
1075
|
+
return false unless id
|
1076
|
+
|
1077
|
+
prefix_options, query_options = split_options(options[:params])
|
1078
|
+
path = element_path(id, prefix_options, query_options)
|
1079
|
+
response = connection.head(path, headers)
|
1080
|
+
|
1081
|
+
(200..206).include?(response.code.to_i)
|
1082
1082
|
rescue ActiveResource::ResourceNotFound, ActiveResource::ResourceGone
|
1083
1083
|
false
|
1084
1084
|
end
|
@@ -211,7 +211,7 @@ module ActiveResource
|
|
211
211
|
|
212
212
|
# Builds headers for request to remote service.
|
213
213
|
def build_request_headers(headers, http_method, uri)
|
214
|
-
authorization_header(http_method, uri).update(default_header).update(http_format_header(http_method)).update(headers)
|
214
|
+
authorization_header(http_method, uri).update(default_header).update(http_format_header(http_method)).update(headers.to_hash)
|
215
215
|
end
|
216
216
|
|
217
217
|
def response_auth_header
|
@@ -119,7 +119,7 @@ module ActiveResource
|
|
119
119
|
|
120
120
|
private
|
121
121
|
def custom_method_element_url(method_name, options = {})
|
122
|
-
"#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{id}/#{method_name}#{self.class.format_extension}#{self.class.__send__(:query_string, options)}"
|
122
|
+
"#{self.class.prefix(prefix_options)}#{self.class.collection_name}/#{URI.encode_www_form_component(id.to_s)}/#{method_name}#{self.class.format_extension}#{self.class.__send__(:query_string, options)}"
|
123
123
|
end
|
124
124
|
|
125
125
|
def custom_method_new_element_url(method_name, options = {})
|
@@ -58,12 +58,12 @@ module ActiveResource
|
|
58
58
|
end
|
59
59
|
|
60
60
|
[ :post, :patch, :put, :get, :delete, :head ].each do |method|
|
61
|
-
# def post(path, request_headers = {}, body = nil, status = 200, response_headers = {})
|
62
|
-
# @responses[Request.new(:post, path, nil, request_headers)] = Response.new(body || "", status, response_headers)
|
61
|
+
# def post(path, request_headers = {}, body = nil, status = 200, response_headers = {}, options: {})
|
62
|
+
# @responses[Request.new(:post, path, nil, request_headers, options)] = Response.new(body || "", status, response_headers)
|
63
63
|
# end
|
64
64
|
module_eval <<-EOE, __FILE__, __LINE__ + 1
|
65
|
-
def #{method}(path, request_headers = {}, body = nil, status = 200, response_headers = {})
|
66
|
-
request = Request.new(:#{method}, path, nil, request_headers)
|
65
|
+
def #{method}(path, request_headers = {}, body = nil, status = 200, response_headers = {}, options = {})
|
66
|
+
request = Request.new(:#{method}, path, nil, request_headers, options)
|
67
67
|
response = Response.new(body || "", status, response_headers)
|
68
68
|
|
69
69
|
delete_duplicate_responses(request)
|
@@ -244,8 +244,8 @@ module ActiveResource
|
|
244
244
|
{ true => %w(post patch put),
|
245
245
|
false => %w(get delete head) }.each do |has_body, methods|
|
246
246
|
methods.each do |method|
|
247
|
-
# def post(path, body, headers)
|
248
|
-
# request = ActiveResource::Request.new(:post, path, body, headers)
|
247
|
+
# def post(path, body, headers, options = {})
|
248
|
+
# request = ActiveResource::Request.new(:post, path, body, headers, options)
|
249
249
|
# self.class.requests << request
|
250
250
|
# if response = self.class.responses.assoc(request)
|
251
251
|
# response[1]
|
@@ -254,8 +254,8 @@ module ActiveResource
|
|
254
254
|
# end
|
255
255
|
# end
|
256
256
|
module_eval <<-EOE, __FILE__, __LINE__ + 1
|
257
|
-
def #{method}(path, #{'body, ' if has_body}headers)
|
258
|
-
request = ActiveResource::Request.new(:#{method}, path, #{has_body ? 'body, ' : 'nil, '}headers)
|
257
|
+
def #{method}(path, #{'body, ' if has_body}headers, options = {})
|
258
|
+
request = ActiveResource::Request.new(:#{method}, path, #{has_body ? 'body, ' : 'nil, '}headers, options)
|
259
259
|
self.class.requests << request
|
260
260
|
if response = self.class.responses.assoc(request)
|
261
261
|
response[1]
|
@@ -279,19 +279,34 @@ module ActiveResource
|
|
279
279
|
class Request
|
280
280
|
attr_accessor :path, :method, :body, :headers
|
281
281
|
|
282
|
-
def initialize(method, path, body = nil, headers = {})
|
283
|
-
@method, @path, @body, @headers = method, path, body, headers
|
282
|
+
def initialize(method, path, body = nil, headers = {}, options = {})
|
283
|
+
@method, @path, @body, @headers, @options = method, path, body, headers, options
|
284
284
|
end
|
285
285
|
|
286
286
|
def ==(req)
|
287
|
-
|
287
|
+
same_path?(req) && method == req.method && headers_match?(req)
|
288
288
|
end
|
289
289
|
|
290
290
|
def to_s
|
291
291
|
"<#{method.to_s.upcase}: #{path} [#{headers}] (#{body})>"
|
292
292
|
end
|
293
293
|
|
294
|
+
# Removes query parameters from the path.
|
295
|
+
#
|
296
|
+
# @return [String] the path without query parameters
|
297
|
+
def remove_query_params_from_path
|
298
|
+
path.split("?").first
|
299
|
+
end
|
300
|
+
|
294
301
|
private
|
302
|
+
def same_path?(req)
|
303
|
+
if @options && @options[:omit_query_in_path]
|
304
|
+
remove_query_params_from_path == req.remove_query_params_from_path
|
305
|
+
else
|
306
|
+
path == req.path
|
307
|
+
end
|
308
|
+
end
|
309
|
+
|
295
310
|
def headers_match?(req)
|
296
311
|
# Ignore format header on equality if it's not defined
|
297
312
|
format_header = ActiveResource::Connection::HTTP_FORMAT_HEADER_NAMES[method]
|
@@ -11,5 +11,24 @@ module ActiveResource
|
|
11
11
|
def [](key)
|
12
12
|
super || @parent_hash[key]
|
13
13
|
end
|
14
|
+
|
15
|
+
# Merges the flattened parent hash (if it's an InheritingHash)
|
16
|
+
# with ourself
|
17
|
+
def to_hash
|
18
|
+
@parent_hash.to_hash.merge(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
# So we can see the merged object in IRB or the Rails console
|
22
|
+
def pretty_print(pp)
|
23
|
+
pp.pp_hash to_hash
|
24
|
+
end
|
25
|
+
|
26
|
+
def inspect
|
27
|
+
to_hash.inspect
|
28
|
+
end
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
inspect
|
32
|
+
end
|
14
33
|
end
|
15
34
|
end
|
@@ -160,7 +160,7 @@ module ActiveResource
|
|
160
160
|
# my_person.valid?
|
161
161
|
# # => false
|
162
162
|
#
|
163
|
-
def valid?
|
163
|
+
def valid?(context = nil)
|
164
164
|
run_callbacks :validate do
|
165
165
|
super
|
166
166
|
load_remote_errors(@remote_errors, true) if defined?(@remote_errors) && @remote_errors.present?
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeresource
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 6.
|
4
|
+
version: 6.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -135,9 +135,9 @@ licenses:
|
|
135
135
|
- MIT
|
136
136
|
metadata:
|
137
137
|
bug_tracker_uri: https://github.com/rails/activeresource/issues
|
138
|
-
changelog_uri: https://github.com/rails/activeresource/releases/tag/v6.
|
138
|
+
changelog_uri: https://github.com/rails/activeresource/releases/tag/v6.1.0
|
139
139
|
documentation_uri: http://rubydoc.info/gems/activeresource
|
140
|
-
source_code_uri: https://github.com/rails/activeresource/tree/v6.
|
140
|
+
source_code_uri: https://github.com/rails/activeresource/tree/v6.1.0
|
141
141
|
rubygems_mfa_required: 'true'
|
142
142
|
post_install_message:
|
143
143
|
rdoc_options: []
|
@@ -154,7 +154,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
154
154
|
- !ruby/object:Gem::Version
|
155
155
|
version: '0'
|
156
156
|
requirements: []
|
157
|
-
rubygems_version: 3.
|
157
|
+
rubygems_version: 3.4.10
|
158
158
|
signing_key:
|
159
159
|
specification_version: 4
|
160
160
|
summary: REST modeling framework (part of Rails).
|