aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel/lib/active_model/serializers
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2009-07-12 16:29:15 +0200
committerJosé Valim <jose.valim@gmail.com>2009-07-12 16:29:15 +0200
commit3075ae0611625657de052a2ad93cf083d24bb803 (patch)
treef421dda228ef1bbe79a31c9c5b95d502b041adf9 /activemodel/lib/active_model/serializers
parentcca16a015d52a8fde0d4f66970ee333900ca21cc (diff)
parentc863388039ff6e97447be86184d41fbf30f0f389 (diff)
downloadrails-3075ae0611625657de052a2ad93cf083d24bb803.tar.gz
rails-3075ae0611625657de052a2ad93cf083d24bb803.tar.bz2
rails-3075ae0611625657de052a2ad93cf083d24bb803.zip
Solving merge conflicts.
Diffstat (limited to 'activemodel/lib/active_model/serializers')
-rw-r--r--activemodel/lib/active_model/serializers/xml.rb49
1 files changed, 27 insertions, 22 deletions
diff --git a/activemodel/lib/active_model/serializers/xml.rb b/activemodel/lib/active_model/serializers/xml.rb
index d187859b44..7cdd281223 100644
--- a/activemodel/lib/active_model/serializers/xml.rb
+++ b/activemodel/lib/active_model/serializers/xml.rb
@@ -17,6 +17,15 @@ module ActiveModel
@value = compute_value
end
+ # There is a significant speed improvement if the value
+ # does not need to be escaped, as <tt>tag!</tt> escapes all values
+ # to ensure that valid XML is generated. For known binary
+ # values, it is at least an order of magnitude faster to
+ # Base64 encode binary values and directly put them in the
+ # output XML than to pass the original value or the Base64
+ # encoded value to the <tt>tag!</tt> method. It definitely makes
+ # no sense to Base64 encode the value and then give it to
+ # <tt>tag!</tt>, since that just adds additional overhead.
def needs_encoding?
![ :binary, :date, :datetime, :boolean, :float, :integer ].include?(type)
end
@@ -105,28 +114,6 @@ module ActiveModel
end
end
- def add_attributes
- (serializable_attributes + serializable_method_attributes).each do |attribute|
- add_tag(attribute)
- end
- end
-
- def add_procs
- if procs = options.delete(:procs)
- [ *procs ].each do |proc|
- proc.call(options)
- end
- end
- end
-
- def add_tag(attribute)
- builder.tag!(
- reformat_name(attribute.name),
- attribute.value.to_s,
- attribute.decorations(!options[:skip_types])
- )
- end
-
def serialize
args = [root]
@@ -152,6 +139,24 @@ module ActiveModel
name = name.camelize if camelize?
dasherize? ? name.dasherize : name
end
+
+ def add_attributes
+ (serializable_attributes + serializable_method_attributes).each do |attribute|
+ builder.tag!(
+ reformat_name(attribute.name),
+ attribute.value.to_s,
+ attribute.decorations(!options[:skip_types])
+ )
+ end
+ end
+
+ def add_procs
+ if procs = options.delete(:procs)
+ [ *procs ].each do |proc|
+ proc.call(options)
+ end
+ end
+ end
end
def to_xml(options = {}, &block)