activeresource 3.2.22.5 → 5.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +5 -5
  2. data/MIT-LICENSE +2 -2
  3. data/README.rdoc +147 -49
  4. data/lib/active_resource.rb +12 -12
  5. data/lib/active_resource/active_job_serializer.rb +26 -0
  6. data/lib/active_resource/associations.rb +175 -0
  7. data/lib/active_resource/associations/builder/association.rb +33 -0
  8. data/lib/active_resource/associations/builder/belongs_to.rb +16 -0
  9. data/lib/active_resource/associations/builder/has_many.rb +14 -0
  10. data/lib/active_resource/associations/builder/has_one.rb +14 -0
  11. data/lib/active_resource/base.rb +444 -231
  12. data/lib/active_resource/callbacks.rb +22 -0
  13. data/lib/active_resource/collection.rb +94 -0
  14. data/lib/active_resource/connection.rb +112 -105
  15. data/lib/active_resource/custom_methods.rb +24 -14
  16. data/lib/active_resource/exceptions.rb +5 -3
  17. data/lib/active_resource/formats.rb +5 -3
  18. data/lib/active_resource/formats/json_format.rb +4 -1
  19. data/lib/active_resource/formats/xml_format.rb +4 -2
  20. data/lib/active_resource/http_mock.rb +69 -31
  21. data/lib/active_resource/log_subscriber.rb +14 -3
  22. data/lib/active_resource/observing.rb +0 -29
  23. data/lib/active_resource/railtie.rb +14 -3
  24. data/lib/active_resource/reflection.rb +78 -0
  25. data/lib/active_resource/schema.rb +4 -4
  26. data/lib/active_resource/singleton.rb +113 -0
  27. data/lib/active_resource/threadsafe_attributes.rb +66 -0
  28. data/lib/active_resource/validations.rb +56 -14
  29. data/lib/active_resource/version.rb +7 -5
  30. data/lib/activeresource.rb +3 -0
  31. metadata +78 -16
  32. data/CHANGELOG.md +0 -437
  33. data/examples/performance.rb +0 -70
data/CHANGELOG.md DELETED
@@ -1,437 +0,0 @@
1
- ## Rails 3.2.22 (Jun 16, 2015) ##
2
-
3
- * No changes.
4
-
5
-
6
- ## Rails 3.2.19 (Jul 2, 2014) ##
7
-
8
- * No changes.
9
-
10
-
11
- ## Rails 3.2.18 (May 6, 2014) ##
12
-
13
- * No changes.
14
-
15
-
16
- ## Rails 3.2.17 (Feb 18, 2014) ##
17
-
18
- * No changes.
19
-
20
-
21
- ## Rails 3.2.16 (Dec 3, 2013) ##
22
-
23
- * No changes.
24
-
25
-
26
- ## Rails 3.2.15 (Oct 16, 2013) ##
27
-
28
- * No changes.
29
-
30
-
31
- ## Rails 3.2.14 (Jul 22, 2013) ##
32
-
33
- * Fixes an issue that ActiveResource models ignores ActiveResource::Base.include_root_in_json.
34
- Backported from the now separate repo rails/activeresouce.
35
-
36
- *Xinjiang Lu*
37
-
38
-
39
- ## Rails 3.2.13 (Mar 18, 2013) ##
40
-
41
- * No changes.
42
-
43
-
44
- ## Rails 3.2.12 (Feb 11, 2013) ##
45
-
46
- * No changes.
47
-
48
-
49
- ## Rails 3.2.11 (Jan 8, 2013) ##
50
-
51
- * No changes.
52
-
53
-
54
- ## Rails 3.2.10 (Jan 2, 2013) ##
55
-
56
- * No changes.
57
-
58
-
59
- ## Rails 3.2.9 (Nov 12, 2012) ##
60
-
61
- * No changes.
62
-
63
-
64
- ## Rails 3.2.8 (Aug 9, 2012) ##
65
-
66
- * No changes.
67
-
68
-
69
- ## Rails 3.2.7 (Jul 26, 2012) ##
70
-
71
- * No changes.
72
-
73
-
74
- ## Rails 3.2.6 (Jun 12, 2012) ##
75
-
76
- * No changes.
77
-
78
-
79
- ## Rails 3.2.5 (Jun 1, 2012) ##
80
-
81
- * No changes.
82
-
83
-
84
- ## Rails 3.2.4 (May 31, 2012) ##
85
-
86
- * No changes.
87
-
88
-
89
- ## Rails 3.2.3 (March 30, 2012) ##
90
-
91
- * No changes.
92
-
93
-
94
- ## Rails 3.2.2 (March 1, 2012) ##
95
-
96
- * No changes.
97
-
98
-
99
- ## Rails 3.2.1 (January 26, 2012) ##
100
-
101
- * Documentation fixes.
102
-
103
-
104
- ## Rails 3.2.0 (January 20, 2012) ##
105
-
106
- * Redirect responses: 303 See Other and 307 Temporary Redirect now behave like
107
- 301 Moved Permanently and 302 Found. GH #3302.
108
-
109
- *Jim Herz*
110
-
111
-
112
- ## Rails 3.1.1 (October 7, 2011) ##
113
-
114
- * No changes.
115
-
116
-
117
- ## Rails 3.1.0 (August 30, 2011) ##
118
-
119
- * The default format has been changed to JSON for all requests. If you want to continue to use XML you will need to set `self.format = :xml` in the class. eg.
120
-
121
- class User < ActiveResource::Base self.format = :xml
122
- end
123
-
124
- ## Rails 3.0.7 (April 18, 2011) ##
125
-
126
- * No changes.
127
-
128
-
129
- * Rails 3.0.6 (April 5, 2011)
130
-
131
- * No changes.
132
-
133
-
134
- ## Rails 3.0.5 (February 26, 2011) ##
135
-
136
- * No changes.
137
-
138
-
139
- ## Rails 3.0.4 (February 8, 2011) ##
140
-
141
- * No changes.
142
-
143
-
144
- ## Rails 3.0.3 (November 16, 2010) ##
145
-
146
- * No changes.
147
-
148
-
149
- ## Rails 3.0.2 (November 15, 2010) ##
150
-
151
- * No changes
152
-
153
-
154
- ## Rails 3.0.1 (October 15, 2010) ##
155
-
156
- * No Changes, just a version bump.
157
-
158
-
159
- ## Rails 3.0.0 (August 29, 2010) ##
160
-
161
- * JSON: set Base.include_root_in_json = true to include a root value in the JSON: {"post": {"title": ...}}. Mirrors the Active Record option. *Santiago Pastorino*
162
-
163
- * Add support for errors in JSON format. #1956 *Fabien Jakimowicz*
164
-
165
- * Recognizes 410 as Resource Gone. #2316 *Jordan Brough, Jatinder Singh*
166
-
167
- * More thorough SSL support. #2370 *Roy Nicholson*
168
-
169
- * HTTP proxy support. #2133 *Marshall Huss, Sébastien Dabet*
170
-
171
-
172
- ## 2.3.2 Final (March 15, 2009) ##
173
-
174
- * Nothing new, just included in 2.3.2
175
-
176
-
177
- ## 2.2.1 RC2 (November 14th, 2008) ##
178
-
179
- * Fixed that ActiveResource#post would post an empty string when it shouldn't be posting anything #525 *Paolo Angelini*
180
-
181
-
182
- ## 2.2.0 RC1 (October 24th, 2008) ##
183
-
184
- * Add ActiveResource::Base#to_xml and ActiveResource::Base#to_json. #1011 *Rasik Pandey, Cody Fauser*
185
-
186
- * Add ActiveResource::Base.find(:last). [#754 state:resolved] (Adrian Mugnolo)
187
-
188
- * Fixed problems with the logger used if the logging string included %'s [#840 state:resolved] (Jamis Buck)
189
-
190
- * Fixed Base#exists? to check status code as integer [#299 state:resolved] (Wes Oldenbeuving)
191
-
192
-
193
- ## 2.1.0 (May 31st, 2008) ##
194
-
195
- * Fixed response logging to use length instead of the entire thing (seangeo) *#27*
196
-
197
- * Fixed that to_param should be used and honored instead of hardcoding the id #11406 *gspiers*
198
-
199
- * Improve documentation. *Ryan Bigg, Jan De Poorter, Cheah Chu Yeow, Xavier Shay, Jack Danger Canty, Emilio Tagua, Xavier Noria, Sunny Ripert*
200
-
201
- * Use HEAD instead of GET in exists? *bscofield*
202
-
203
- * Fix small documentation typo. Closes #10670 *Luca Guidi*
204
-
205
- * find_or_create_resource_for handles module nesting. #10646 *xavier*
206
-
207
- * Allow setting ActiveResource::Base#format before #site. *Rick Olson*
208
-
209
- * Support agnostic formats when calling custom methods. Closes #10635 *joerichsen*
210
-
211
- * Document custom methods. #10589 *Cheah Chu Yeow*
212
-
213
- * Ruby 1.9 compatibility. *Jeremy Kemper*
214
-
215
-
216
- ## 2.0.2 (December 16th, 2007) ##
217
-
218
- * Added more specific exceptions for 400, 401, and 403 (all descending from ClientError so existing rescues will work) #10326 *trek*
219
-
220
- * Correct empty response handling. #10445 *seangeo*
221
-
222
-
223
- ## 2.0.1 (December 7th, 2007) ##
224
-
225
- * Don't cache net/http object so that ActiveResource is more thread-safe. Closes #10142 *kou*
226
-
227
- * Update XML documentation examples to include explicit type attributes. Closes #9754 *Josh Susser*
228
-
229
- * Added one-off declarations of mock behavior [David Heinemeier Hansson]. Example:
230
-
231
- Before:
232
- ActiveResource::HttpMock.respond_to do |mock|
233
- mock.get "/people/1.xml", {}, "<person><name>David</name></person>"
234
- end
235
-
236
- Now:
237
- ActiveResource::HttpMock.respond_to.get "/people/1.xml", {}, "<person><name>David</name></person>"
238
-
239
- * Added ActiveResource.format= which defaults to :xml but can also be set to :json [David Heinemeier Hansson]. Example:
240
-
241
- class Person < ActiveResource::Base
242
- self.site = "http://app/"
243
- self.format = :json
244
- end
245
-
246
- person = Person.find(1) # => GET http://app/people/1.json
247
- person.name = "David"
248
- person.save # => PUT http://app/people/1.json {name: "David"}
249
-
250
- Person.format = :xml
251
- person.name = "Mary"
252
- person.save # => PUT http://app/people/1.json <person><name>Mary</name></person>
253
-
254
- * Fix reload error when path prefix is used. #8727 *Ian Warshak*
255
-
256
- * Remove ActiveResource::Struct because it hasn't proven very useful. Creating a new ActiveResource::Base subclass is often less code and always clearer. #8612 *Josh Peek*
257
-
258
- * Fix query methods on resources. *Cody Fauser*
259
-
260
- * pass the prefix_options to the instantiated record when using find without a specific id. Closes #8544 *Eloy Duran*
261
-
262
- * Recognize and raise an exception on 405 Method Not Allowed responses. #7692 *Josh Peek*
263
-
264
- * Handle string and symbol param keys when splitting params into prefix params and query params.
265
-
266
- Comment.find(:all, :params => { :article_id => 5, :page => 2 }) or Comment.find(:all, :params => { 'article_id' => 5, :page => 2 })
267
-
268
- * Added find-one with symbol [David Heinemeier Hansson]. Example: Person.find(:one, :from => :leader) # => GET /people/leader.xml
269
-
270
- * BACKWARDS INCOMPATIBLE: Changed the finder API to be more extensible with :params and more strict usage of scopes [David Heinemeier Hansson]. Changes:
271
-
272
- Person.find(:all, :title => "CEO") ...becomes: Person.find(:all, :params => { :title => "CEO" })
273
- Person.find(:managers) ...becomes: Person.find(:all, :from => :managers)
274
- Person.find("/companies/1/manager.xml") ...becomes: Person.find(:one, :from => "/companies/1/manager.xml")
275
-
276
- * Add support for setting custom headers per Active Resource model *Rick Olson*
277
-
278
- class Project
279
- headers['X-Token'] = 'foo'
280
- end
281
-
282
- \# makes the GET request with the custom X-Token header
283
- Project.find(:all)
284
-
285
- * Added find-by-path options to ActiveResource::Base.find [David Heinemeier Hansson]. Examples:
286
-
287
- employees = Person.find(:all, :from => "/companies/1/people.xml") # => GET /companies/1/people.xml
288
- manager = Person.find("/companies/1/manager.xml") # => GET /companies/1/manager.xml
289
-
290
-
291
- * Added support for using classes from within a single nested module [David Heinemeier Hansson]. Example:
292
-
293
- module Highrise
294
- class Note < ActiveResource::Base
295
- self.site = "http://37s.sunrise.i:3000"
296
- end
297
-
298
- class Comment < ActiveResource::Base
299
- self.site = "http://37s.sunrise.i:3000"
300
- end
301
- end
302
-
303
- assert_kind_of Highrise::Comment, Note.find(1).comments.first
304
-
305
-
306
- * Added load_attributes_from_response as a way of loading attributes from other responses than just create *David Heinemeier Hansson*
307
-
308
- class Highrise::Task < ActiveResource::Base
309
- def complete
310
- load_attributes_from_response(post(:complete))
311
- end
312
- end
313
-
314
- ...will set "done_at" when complete is called.
315
-
316
-
317
- * Added support for calling custom methods #6979 *rwdaigle*
318
-
319
- Person.find(:managers) # => GET /people/managers.xml
320
- Kase.find(1).post(:close) # => POST /kases/1/close.xml
321
-
322
- * Remove explicit prefix_options parameter for ActiveResource::Base#initialize. *Rick Olson*
323
- ActiveResource splits the prefix_options from it automatically.
324
-
325
- * Allow ActiveResource::Base.delete with custom prefix. *Rick Olson*
326
-
327
- * Add ActiveResource::Base#dup *Rick Olson*
328
-
329
- * Fixed constant warning when fetching the same object multiple times *David Heinemeier Hansson*
330
-
331
- * Added that saves which get a body response (and not just a 201) will use that response to update themselves *David Heinemeier Hansson*
332
-
333
- * Disregard namespaces from the default element name, so Highrise::Person will just try to fetch from "/people", not "/highrise/people" *David Heinemeier Hansson*
334
-
335
- * Allow array and hash query parameters. #7756 *Greg Spurrier*
336
-
337
- * Loading a resource preserves its prefix_options. #7353 *Ryan Daigle*
338
-
339
- * Carry over the convenience of #create from ActiveRecord. Closes #7340. *Ryan Daigle*
340
-
341
- * Increase ActiveResource::Base test coverage. Closes #7173, #7174 *Rich Collins*
342
-
343
- * Interpret 422 Unprocessable Entity as ResourceInvalid. #7097 *dkubb*
344
-
345
- * Mega documentation patches. #7025, #7069 *rwdaigle*
346
-
347
- * Base.exists?(id, options) and Base#exists? check whether the resource is found. #6970 *rwdaigle*
348
-
349
- * Query string support. *untext, Jeremy Kemper*
350
- # GET /forums/1/topics.xml?sort=created_at
351
- Topic.find(:all, :forum_id => 1, :sort => 'created_at')
352
-
353
- * Base#==, eql?, and hash methods. == returns true if its argument is identical to self or if it's an instance of the same class, is not new?, and has the same id. eql? is an alias for ==. hash delegates to id. *Jeremy Kemper*
354
-
355
- * Allow subclassed resources to share the site info *Rick Olson, Jeremy Kemper*
356
- d class BeastResource < ActiveResource::Base
357
- self.site = 'http://beast.caboo.se'
358
- end
359
-
360
- class Forum < BeastResource
361
- # taken from BeastResource
362
- # self.site = 'http://beast.caboo.se'
363
- end
364
-
365
- class Topic < BeastResource
366
- self.site += '/forums/:forum_id'
367
- end
368
-
369
- * Fix issues with ActiveResource collection handling. Closes #6291. *bmilekic*
370
-
371
- * Use attr_accessor_with_default to dry up attribute initialization. References #6538. *Stuart Halloway*
372
-
373
- * Add basic logging support for logging outgoing requests. *Jamis Buck*
374
-
375
- * Add Base.delete for deleting resources without having to instantiate them first. *Jamis Buck*
376
-
377
- * Make #save behavior mimic AR::Base#save (true on success, false on failure). *Jamis Buck*
378
-
379
- * Add Basic HTTP Authentication to ActiveResource (closes #6305). *jonathan*
380
-
381
- * Extracted #id_from_response as an entry point for customizing how a created resource gets its own ID.
382
- By default, it extracts from the Location response header.
383
-
384
- * Optimistic locking: raise ActiveResource::ResourceConflict on 409 Conflict response. *Jeremy Kemper*
385
-
386
- # Example controller action
387
- def update
388
- @person.save!
389
- rescue ActiveRecord::StaleObjectError
390
- render :xml => @person.reload.to_xml, :status => '409 Conflict'
391
- end
392
-
393
- * Basic validation support *Rick Olson*
394
-
395
- Parses the xml response of ActiveRecord::Errors#to_xml with a similar interface to ActiveRecord::Errors.
396
-
397
- render :xml => @person.errors.to_xml, :status => '400 Validation Error'
398
-
399
- * Deep hashes are converted into collections of resources. *Jeremy Kemper*
400
- Person.new :name => 'Bob',
401
- :address => { :id => 1, :city => 'Portland' },
402
- :contacts => [{ :id => 1 }, { :id => 2 }]
403
- Looks for Address and Contact resources and creates them if unavailable.
404
- So clients can fetch a complex resource in a single request if you e.g.
405
- render :xml => @person.to_xml(:include => [:address, :contacts])
406
- in your controller action.
407
-
408
- * Major updates *Rick Olson*
409
-
410
- * Add full support for find/create/update/destroy
411
- * Add support for specifying prefixes.
412
- * Allow overriding of element_name, collection_name, and primary key
413
- * Provide simpler HTTP mock interface for testing
414
-
415
- # rails routing code
416
- map.resources :posts do |post|
417
- post.resources :comments
418
- end
419
-
420
- # ActiveResources
421
- class Post < ActiveResource::Base
422
- self.site = "http://37s.sunrise.i:3000/"
423
- end
424
-
425
- class Comment < ActiveResource::Base
426
- self.site = "http://37s.sunrise.i:3000/posts/:post_id/"
427
- end
428
-
429
- @post = Post.find 5
430
- @comments = Comment.find :all, :post_id => @post.id
431
-
432
- @comment = Comment.new({:body => 'hello world'}, {:post_id => @post.id})
433
- @comment.save
434
-
435
- * Base.site= accepts URIs. 200...400 are valid response codes. PUT and POST request bodies default to ''. *Jeremy Kemper*
436
-
437
- * Initial checkin: object-oriented client for restful HTTP resources which follow the Rails convention. *David Heinemeier Hansson*
@@ -1,70 +0,0 @@
1
- require 'rubygems'
2
- require 'active_resource'
3
- require 'benchmark'
4
-
5
- TIMES = (ENV['N'] || 10_000).to_i
6
-
7
- # deep nested resource
8
- attrs = {
9
- :id => 1,
10
- :name => 'Luis',
11
- :age => 21,
12
- :friends => [
13
- {
14
- :name => 'JK',
15
- :age => 24,
16
- :colors => ['red', 'green', 'blue'],
17
- :brothers => [
18
- {
19
- :name => 'Mateo',
20
- :age => 35,
21
- :children => [{ :name => 'Edith', :age => 5 }, { :name => 'Martha', :age => 4 }]
22
- },
23
- {
24
- :name => 'Felipe',
25
- :age => 33,
26
- :children => [{ :name => 'Bryan', :age => 1 }, { :name => 'Luke', :age => 0 }]
27
- }
28
- ]
29
- },
30
- {
31
- :name => 'Eduardo',
32
- :age => 20,
33
- :colors => [],
34
- :brothers => [
35
- {
36
- :name => 'Sebas',
37
- :age => 23,
38
- :children => [{ :name => 'Andres', :age => 0 }, { :name => 'Jorge', :age => 2 }]
39
- },
40
- {
41
- :name => 'Elsa',
42
- :age => 19,
43
- :children => [{ :name => 'Natacha', :age => 1 }]
44
- },
45
- {
46
- :name => 'Milena',
47
- :age => 16,
48
- :children => []
49
- }
50
- ]
51
- }
52
- ]
53
- }
54
-
55
- class Customer < ActiveResource::Base
56
- self.site = "http://37s.sunrise.i:3000"
57
- end
58
-
59
- module Nested
60
- class Customer < ActiveResource::Base
61
- self.site = "http://37s.sunrise.i:3000"
62
- end
63
- end
64
-
65
- Benchmark.bm(40) do |x|
66
- x.report('Model.new (instantiation)') { TIMES.times { Customer.new } }
67
- x.report('Nested::Model.new (instantiation)') { TIMES.times { Nested::Customer.new } }
68
- x.report('Model.new (setting attributes)') { TIMES.times { Customer.new attrs } }
69
- x.report('Nested::Model.new (setting attributes)') { TIMES.times { Nested::Customer.new attrs } }
70
- end