aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-12-10 14:53:18 -0800
committerJeremy Kemper <jeremy@bitsweat.net>2008-12-10 14:53:18 -0800
commitd45e2c733d471b0c87f7cf721376ca4802450121 (patch)
treef1fc669b183961d67e5ed41e386133e02370aba0 /activerecord/lib/active_record
parentb30ae1974851b20ef430df9de17e6e79e5b25ad2 (diff)
parentaa5cdb0d47fb5484bfdde8244df7efeb2175bf3a (diff)
downloadrails-d45e2c733d471b0c87f7cf721376ca4802450121.tar.gz
rails-d45e2c733d471b0c87f7cf721376ca4802450121.tar.bz2
rails-d45e2c733d471b0c87f7cf721376ca4802450121.zip
Merge branch 'master' of git@github.com:rails/rails
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/serializers/xml_serializer.rb23
1 files changed, 16 insertions, 7 deletions
diff --git a/activerecord/lib/active_record/serializers/xml_serializer.rb b/activerecord/lib/active_record/serializers/xml_serializer.rb
index d171b742f5..4749823b94 100644
--- a/activerecord/lib/active_record/serializers/xml_serializer.rb
+++ b/activerecord/lib/active_record/serializers/xml_serializer.rb
@@ -23,11 +23,12 @@ module ActiveRecord #:nodoc:
# </topic>
#
# This behavior can be controlled with <tt>:only</tt>, <tt>:except</tt>,
- # <tt>:skip_instruct</tt>, <tt>:skip_types</tt> and <tt>:dasherize</tt>.
+ # <tt>:skip_instruct</tt>, <tt>:skip_types</tt>, <tt>:dasherize</tt> and <tt>:camelize</tt> .
# The <tt>:only</tt> and <tt>:except</tt> options are the same as for the
# +attributes+ method. The default is to dasherize all column names, but you
- # can disable this setting <tt>:dasherize</tt> to +false+. To not have the
- # column type included in the XML output set <tt>:skip_types</tt> to +true+.
+ # can disable this setting <tt>:dasherize</tt> to +false+. Setting <tt>:camelize</tt>
+ # to +true+ will camelize all column names - this also overrides <tt>:dasherize</tt>.
+ # To not have the column type included in the XML output set <tt>:skip_types</tt> to +true+.
#
# For instance:
#
@@ -178,13 +179,22 @@ module ActiveRecord #:nodoc:
def root
root = (options[:root] || @record.class.to_s.underscore).to_s
- dasherize? ? root.dasherize : root
+ reformat_name(root)
end
def dasherize?
!options.has_key?(:dasherize) || options[:dasherize]
end
+ def camelize?
+ options.has_key?(:camelize) && options[:camelize]
+ end
+
+ def reformat_name(name)
+ name = name.camelize if camelize?
+ dasherize? ? name.dasherize : name
+ end
+
def serializable_attributes
serializable_attribute_names.collect { |name| Attribute.new(name, @record) }
end
@@ -212,7 +222,7 @@ module ActiveRecord #:nodoc:
def add_tag(attribute)
builder.tag!(
- dasherize? ? attribute.name.dasherize : attribute.name,
+ reformat_name(attribute.name),
attribute.value.to_s,
attribute.decorations(!options[:skip_types])
)
@@ -220,8 +230,7 @@ module ActiveRecord #:nodoc:
def add_associations(association, records, opts)
if records.is_a?(Enumerable)
- tag = association.to_s
- tag = tag.dasherize if dasherize?
+ tag = reformat_name(association.to_s)
if records.empty?
builder.tag!(tag, :type => :array)
else