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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2a0c925e2619c4a4204eebdaea70776a57fec944e9eefeb98982ed8cf425bbc
4
- data.tar.gz: b77c66a74c3fe0d32e16d0ce4eaaec1c772200bda9ea36b2bfba1a3cc4f58b5d
3
+ metadata.gz: eb092fb2d853c88525dc4f656733f5ba9c4865d1092ee376f598c1ec944c0e02
4
+ data.tar.gz: c907a425824ed9227dbc9b48195bf38c0ffb9d6312ab13a63270b973450482b8
5
5
  SHA512:
6
- metadata.gz: 9116078833a262f5a4d184a9cd080f3a29bfc5c07481cf352dd87baa735ba0dfae6159a35ac37ea1ad2e121348a33d958151a048af8dbb6e85e3a387076de3b5
7
- data.tar.gz: 02e8b7e3aa1fd89f70f67b2696d778bf0c4a5d89c4b6f779ec3ecffc6a099374c06515ec2bfcb4e7175a518f00543f16b1b691670378c2533fcf353ce82cb96f
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 verubys available in the HTTP specification:
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.
@@ -1072,13 +1072,13 @@ module ActiveResource
1072
1072
  #
1073
1073
  # Note.exists(1349) # => false
1074
1074
  def exists?(id, options = {})
1075
- if id
1076
- prefix_options, query_options = split_options(options[:params])
1077
- path = element_path(id, prefix_options, query_options)
1078
- response = connection.head(path, headers)
1079
- (200..206).include? response.code.to_i
1080
- end
1081
- # id && !find_single(id, options).nil?
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
- path == req.path && method == req.method && headers_match?(req)
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?
@@ -3,7 +3,7 @@
3
3
  module ActiveResource
4
4
  module VERSION # :nodoc:
5
5
  MAJOR = 6
6
- MINOR = 0
6
+ MINOR = 1
7
7
  TINY = 0
8
8
  PRE = nil
9
9
 
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.0.0
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: 2022-01-10 00:00:00.000000000 Z
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.0.0
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.0.0
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.2.32
157
+ rubygems_version: 3.4.10
158
158
  signing_key:
159
159
  specification_version: 4
160
160
  summary: REST modeling framework (part of Rails).