aboutsummaryrefslogtreecommitdiffstats
path: root/activeresource/lib
diff options
context:
space:
mode:
Diffstat (limited to 'activeresource/lib')
-rw-r--r--activeresource/lib/active_resource/base.rb14
-rw-r--r--activeresource/lib/active_resource/schema.rb2
2 files changed, 11 insertions, 5 deletions
diff --git a/activeresource/lib/active_resource/base.rb b/activeresource/lib/active_resource/base.rb
index ad994214f6..b976844c1c 100644
--- a/activeresource/lib/active_resource/base.rb
+++ b/activeresource/lib/active_resource/base.rb
@@ -551,11 +551,9 @@ module ActiveResource
@headers ||= {}
end
- # Do not include any modules in the default element name. This makes it easier to seclude ARes objects
- # in a separate namespace without having to set element_name repeatedly.
- attr_accessor_with_default(:element_name) { ActiveSupport::Inflector.underscore(to_s.split("::").last) } #:nodoc:
-
+ attr_accessor_with_default(:element_name) { model_name.element } #:nodoc:
attr_accessor_with_default(:collection_name) { ActiveSupport::Inflector.pluralize(element_name) } #:nodoc:
+
attr_accessor_with_default(:primary_key, 'id') #:nodoc:
# Gets the \prefix for a resource's nested URL (e.g., <tt>prefix/collectionname/1.xml</tt>)
@@ -1295,6 +1293,14 @@ module ActiveResource
end
end
+ def to_json(options={})
+ super({ :root => self.class.element_name }.merge(options))
+ end
+
+ def to_xml(options={})
+ super({ :root => self.class.element_name }.merge(options))
+ end
+
protected
def connection(refresh = false)
self.class.connection(refresh)
diff --git a/activeresource/lib/active_resource/schema.rb b/activeresource/lib/active_resource/schema.rb
index 8368b652c2..5758ac9502 100644
--- a/activeresource/lib/active_resource/schema.rb
+++ b/activeresource/lib/active_resource/schema.rb
@@ -42,7 +42,7 @@ module ActiveResource # :nodoc:
# TODO: We should eventually support all of these:
# %w( string text integer float decimal datetime timestamp time date binary boolean ).each do |attr_type|
KNOWN_ATTRIBUTE_TYPES.each do |attr_type|
- class_eval <<-EOV
+ class_eval <<-EOV, __FILE__, __LINE__ + 1
def #{attr_type.to_s}(*args)
options = args.extract_options!
attr_names = args