class ActiveRecord::XmlSerializer::Attribute
:nodoc:
def compute_type
def compute_type type = if @record.class.serialized_attributes.has_key?(name) :yaml else @record.class.columns_hash[name].try(:type) end case type when :text :string when :time :datetime else type end end
def compute_value
def compute_value value = @record.send(name) if formatter = Hash::XML_FORMATTING[type.to_s] value ? formatter.call(value) : nil else value end end
def decorations(include_types = true)
def decorations(include_types = true) decorations = {} if type == :binary decorations[:encoding] = 'base64' end if include_types && type != :string decorations[:type] = type end if value.nil? decorations[:nil] = true end decorations end
def initialize(name, record)
def initialize(name, record) @name, @record = name, record @type = compute_type @value = compute_value end
def needs_encoding?
no sense to Base64 encode the value and then give it to
encoded value to the tag! method. It definitely makes
output XML than to pass the original value or the Base64
Base64 encode binary values and directly put them in the
values, it is at least an order of magnitude faster to
to ensure that valid XML is generated. For known binary
does not need to be escaped, as tag! escapes all values
There is a significant speed improvement if the value
def needs_encoding? ![ :binary, :date, :datetime, :boolean, :float, :integer ].include?(type) end