activeresource 3.0.0.beta3 → 3.0.0.beta4
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of activeresource might be problematic. Click here for more details.
- data/CHANGELOG +5 -0
- data/lib/active_resource/base.rb +21 -87
- data/lib/active_resource/connection.rb +1 -1
- data/lib/active_resource/schema.rb +1 -1
- data/lib/active_resource/version.rb +1 -1
- metadata +7 -7
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
*Rails 3.0.0 [beta 4] (June 8th, 2010)*
|
2
|
+
|
3
|
+
* 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]
|
4
|
+
|
5
|
+
|
1
6
|
*Rails 3.0.0 [beta 3] (April 13th, 2010)*
|
2
7
|
|
3
8
|
* No changes
|
data/lib/active_resource/base.rb
CHANGED
@@ -251,9 +251,6 @@ module ActiveResource
|
|
251
251
|
# The logger for diagnosing and tracing Active Resource calls.
|
252
252
|
cattr_accessor :logger
|
253
253
|
|
254
|
-
# Controls the top-level behavior of JSON serialization
|
255
|
-
cattr_accessor :include_root_in_json, :instance_writer => false
|
256
|
-
|
257
254
|
class << self
|
258
255
|
# Creates a schema for this resource - setting the attributes that are
|
259
256
|
# known prior to fetching an instance from the remote system.
|
@@ -554,11 +551,9 @@ module ActiveResource
|
|
554
551
|
@headers ||= {}
|
555
552
|
end
|
556
553
|
|
557
|
-
|
558
|
-
# in a separate namespace without having to set element_name repeatedly.
|
559
|
-
attr_accessor_with_default(:element_name) { ActiveSupport::Inflector.underscore(to_s.split("::").last) } #:nodoc:
|
560
|
-
|
554
|
+
attr_accessor_with_default(:element_name) { model_name.element } #:nodoc:
|
561
555
|
attr_accessor_with_default(:collection_name) { ActiveSupport::Inflector.pluralize(element_name) } #:nodoc:
|
556
|
+
|
562
557
|
attr_accessor_with_default(:primary_key, 'id') #:nodoc:
|
563
558
|
|
564
559
|
# Gets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.xml</tt>)
|
@@ -587,12 +582,13 @@ module ActiveResource
|
|
587
582
|
# Clear prefix parameters in case they have been cached
|
588
583
|
@prefix_parameters = nil
|
589
584
|
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
585
|
+
silence_warnings do
|
586
|
+
# Redefine the new methods.
|
587
|
+
instance_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
|
588
|
+
def prefix_source() "#{value}" end
|
589
|
+
def prefix(options={}) "#{prefix_call}" end
|
590
|
+
RUBY_EVAL
|
591
|
+
end
|
596
592
|
rescue
|
597
593
|
logger.error "Couldn't set prefix: #{$!}\n #{code}" if logger
|
598
594
|
raise
|
@@ -1048,11 +1044,6 @@ module ActiveResource
|
|
1048
1044
|
attributes[self.class.primary_key] = id
|
1049
1045
|
end
|
1050
1046
|
|
1051
|
-
# Allows Active Resource objects to be used as parameters in Action Pack URL generation.
|
1052
|
-
def to_param
|
1053
|
-
id && id.to_s
|
1054
|
-
end
|
1055
|
-
|
1056
1047
|
# Test for equality. Resource are equal if and only if +other+ is the same object or
|
1057
1048
|
# is an instance of the same class, is not <tt>new?</tt>, and has the same +id+.
|
1058
1049
|
#
|
@@ -1179,79 +1170,11 @@ module ActiveResource
|
|
1179
1170
|
!new? && self.class.exists?(to_param, :params => prefix_options)
|
1180
1171
|
end
|
1181
1172
|
|
1182
|
-
# Converts the resource to an XML string representation.
|
1183
|
-
#
|
1184
|
-
# ==== Options
|
1185
|
-
# The +options+ parameter is handed off to the +to_xml+ method on each
|
1186
|
-
# attribute, so it has the same options as the +to_xml+ methods in
|
1187
|
-
# Active Support.
|
1188
|
-
#
|
1189
|
-
# * <tt>:indent</tt> - Set the indent level for the XML output (default is +2+).
|
1190
|
-
# * <tt>:dasherize</tt> - Boolean option to determine whether or not element names should
|
1191
|
-
# replace underscores with dashes (default is <tt>false</tt>).
|
1192
|
-
# * <tt>:skip_instruct</tt> - Toggle skipping the +instruct!+ call on the XML builder
|
1193
|
-
# that generates the XML declaration (default is <tt>false</tt>).
|
1194
|
-
#
|
1195
|
-
# ==== Examples
|
1196
|
-
# my_group = SubsidiaryGroup.find(:first)
|
1197
|
-
# my_group.to_xml
|
1198
|
-
# # => <?xml version="1.0" encoding="UTF-8"?>
|
1199
|
-
# # <subsidiary_group> [...] </subsidiary_group>
|
1200
|
-
#
|
1201
|
-
# my_group.to_xml(:dasherize => true)
|
1202
|
-
# # => <?xml version="1.0" encoding="UTF-8"?>
|
1203
|
-
# # <subsidiary-group> [...] </subsidiary-group>
|
1204
|
-
#
|
1205
|
-
# my_group.to_xml(:skip_instruct => true)
|
1206
|
-
# # => <subsidiary_group> [...] </subsidiary_group>
|
1207
|
-
def to_xml(options={})
|
1208
|
-
attributes.to_xml({:root => self.class.element_name}.merge(options))
|
1209
|
-
end
|
1210
|
-
|
1211
|
-
# Coerces to a hash for JSON encoding.
|
1212
|
-
#
|
1213
|
-
# ==== Options
|
1214
|
-
# The +options+ are passed to the +to_json+ method on each
|
1215
|
-
# attribute, so the same options as the +to_json+ methods in
|
1216
|
-
# Active Support.
|
1217
|
-
#
|
1218
|
-
# * <tt>:only</tt> - Only include the specified attribute or list of
|
1219
|
-
# attributes in the serialized output. Attribute names must be specified
|
1220
|
-
# as strings.
|
1221
|
-
# * <tt>:except</tt> - Do not include the specified attribute or list of
|
1222
|
-
# attributes in the serialized output. Attribute names must be specified
|
1223
|
-
# as strings.
|
1224
|
-
#
|
1225
|
-
# ==== Examples
|
1226
|
-
# person = Person.new(:first_name => "Jim", :last_name => "Smith")
|
1227
|
-
# person.to_json
|
1228
|
-
# # => {"first_name": "Jim", "last_name": "Smith"}
|
1229
|
-
#
|
1230
|
-
# person.to_json(:only => ["first_name"])
|
1231
|
-
# # => {"first_name": "Jim"}
|
1232
|
-
#
|
1233
|
-
# person.to_json(:except => ["first_name"])
|
1234
|
-
# # => {"last_name": "Smith"}
|
1235
|
-
def as_json(options = nil)
|
1236
|
-
attributes.as_json(options)
|
1237
|
-
end
|
1238
|
-
|
1239
1173
|
# Returns the serialized string representation of the resource in the configured
|
1240
1174
|
# serialization format specified in ActiveResource::Base.format. The options
|
1241
1175
|
# applicable depend on the configured encoding format.
|
1242
1176
|
def encode(options={})
|
1243
|
-
|
1244
|
-
when ActiveResource::Formats::XmlFormat
|
1245
|
-
self.class.format.encode(attributes, {:root => self.class.element_name}.merge(options))
|
1246
|
-
when ActiveResource::Formats::JsonFormat
|
1247
|
-
if ActiveResource::Base.include_root_in_json
|
1248
|
-
self.class.format.encode({self.class.element_name => attributes}, options)
|
1249
|
-
else
|
1250
|
-
self.class.format.encode(attributes, options)
|
1251
|
-
end
|
1252
|
-
else
|
1253
|
-
self.class.format.encode(attributes, options)
|
1254
|
-
end
|
1177
|
+
send("to_#{self.class.format.extension}", options)
|
1255
1178
|
end
|
1256
1179
|
|
1257
1180
|
# A method to \reload the attributes of this object from the remote web service.
|
@@ -1366,6 +1289,14 @@ module ActiveResource
|
|
1366
1289
|
end
|
1367
1290
|
end
|
1368
1291
|
|
1292
|
+
def to_json(options={})
|
1293
|
+
super({ :root => self.class.element_name }.merge(options))
|
1294
|
+
end
|
1295
|
+
|
1296
|
+
def to_xml(options={})
|
1297
|
+
super({ :root => self.class.element_name }.merge(options))
|
1298
|
+
end
|
1299
|
+
|
1369
1300
|
protected
|
1370
1301
|
def connection(refresh = false)
|
1371
1302
|
self.class.connection(refresh)
|
@@ -1475,5 +1406,8 @@ module ActiveResource
|
|
1475
1406
|
class Base
|
1476
1407
|
extend ActiveModel::Naming
|
1477
1408
|
include CustomMethods, Observing, Validations
|
1409
|
+
include ActiveModel::Conversion
|
1410
|
+
include ActiveModel::Serializers::JSON
|
1411
|
+
include ActiveModel::Serializers::Xml
|
1478
1412
|
end
|
1479
1413
|
end
|
@@ -106,7 +106,7 @@ module ActiveResource
|
|
106
106
|
private
|
107
107
|
# Makes a request to the remote service.
|
108
108
|
def request(method, path, *arguments)
|
109
|
-
result = ActiveSupport::Notifications.instrument("active_resource
|
109
|
+
result = ActiveSupport::Notifications.instrument("request.active_resource") do |payload|
|
110
110
|
payload[:method] = method
|
111
111
|
payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}"
|
112
112
|
payload[:result] = http.send(method, path, *arguments)
|
@@ -42,7 +42,7 @@ module ActiveResource # :nodoc:
|
|
42
42
|
# TODO: We should eventually support all of these:
|
43
43
|
# %w( string text integer float decimal datetime timestamp time date binary boolean ).each do |attr_type|
|
44
44
|
KNOWN_ATTRIBUTE_TYPES.each do |attr_type|
|
45
|
-
class_eval <<-EOV
|
45
|
+
class_eval <<-EOV, __FILE__, __LINE__ + 1
|
46
46
|
def #{attr_type.to_s}(*args)
|
47
47
|
options = args.extract_options!
|
48
48
|
attr_names = args
|
metadata
CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
|
|
6
6
|
- 3
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 3.0.0.
|
9
|
+
- beta4
|
10
|
+
version: 3.0.0.beta4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- David Heinemeier Hansson
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-06-08 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -29,8 +29,8 @@ dependencies:
|
|
29
29
|
- 3
|
30
30
|
- 0
|
31
31
|
- 0
|
32
|
-
-
|
33
|
-
version: 3.0.0.
|
32
|
+
- beta4
|
33
|
+
version: 3.0.0.beta4
|
34
34
|
type: :runtime
|
35
35
|
version_requirements: *id001
|
36
36
|
- !ruby/object:Gem::Dependency
|
@@ -44,8 +44,8 @@ dependencies:
|
|
44
44
|
- 3
|
45
45
|
- 0
|
46
46
|
- 0
|
47
|
-
-
|
48
|
-
version: 3.0.0.
|
47
|
+
- beta4
|
48
|
+
version: 3.0.0.beta4
|
49
49
|
type: :runtime
|
50
50
|
version_requirements: *id002
|
51
51
|
description: REST on Rails. Wrap your RESTful web app with Ruby classes and work with them like Active Record models.
|