diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-01-10 12:14:44 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-01-10 12:14:44 -0800 |
commit | 223a1d9451c88800e9fcc93a726fdebec99e2650 (patch) | |
tree | 207b0b671778ac7a0e00829f6f642256b261cb28 /activerecord/lib/active_record/serializers/xml_serializer.rb | |
parent | 13c6c3cfc59ff0b400b294dce15f32752b0fb5f5 (diff) | |
parent | 9fe69b225cfbf12c02ee1433adf3a5aa17bcdf59 (diff) | |
download | rails-223a1d9451c88800e9fcc93a726fdebec99e2650.tar.gz rails-223a1d9451c88800e9fcc93a726fdebec99e2650.tar.bz2 rails-223a1d9451c88800e9fcc93a726fdebec99e2650.zip |
Merge branch 'master' into savepoints
Diffstat (limited to 'activerecord/lib/active_record/serializers/xml_serializer.rb')
-rw-r--r-- | activerecord/lib/active_record/serializers/xml_serializer.rb | 23 |
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 |