diff options
author | Marcel Molina <marcel@vernix.org> | 2006-04-29 23:00:47 +0000 |
---|---|---|
committer | Marcel Molina <marcel@vernix.org> | 2006-04-29 23:00:47 +0000 |
commit | 3fec943aca9ab73bf00d5dffa3f73452f33bab88 (patch) | |
tree | cd708510c8be8951440580f6a233674b8066e6bf /activerecord/lib/active_record | |
parent | aa72c465ec4aa641e9ea161110a43ad9c02d167b (diff) | |
download | rails-3fec943aca9ab73bf00d5dffa3f73452f33bab88.tar.gz rails-3fec943aca9ab73bf00d5dffa3f73452f33bab88.tar.bz2 rails-3fec943aca9ab73bf00d5dffa3f73452f33bab88.zip |
Allow AR::Base#to_xml to include methods too. Closes #4921. [johan@textdrive.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4314 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index e7fa8434e6..511af69428 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1690,6 +1690,16 @@ module ActiveRecord #:nodoc: # <credit-limit type="integer">50</credit-limit> # </account> # </firm> + # + # To include any methods on the object(s) being called use :methods + # + # firm.to_xml :methods => [ :calculated_earnings, :real_earnings ] + # + # <firm> + # # ... normal attributes as shown above ... + # <calculated-earnings>100000000000000000</calculated-earnings> + # <real-earnings>5</real-earnings> + # </firm> def to_xml(options = {}) options[:root] ||= self.class.to_s.underscore options[:except] = Array(options[:except]) << self.class.inheritance_column unless options[:only] # skip type column @@ -1697,6 +1707,12 @@ module ActiveRecord #:nodoc: attributes_for_xml = attributes(root_only_or_except) + if methods_to_call = options.delete(:methods) + [*methods_to_call].each do |meth| + attributes_for_xml[meth] = send(meth) + end + end + if include_associations = options.delete(:include) include_has_options = include_associations.is_a?(Hash) |