Class: Sequel::XmlSerializer::Attribute

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel/serializer/xml_serializer.rb

Overview

def strip_associations

  p @tag_names
end

Direct Known Subclasses

MethodAttribute

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, record) ⇒ Attribute

Returns a new instance of Attribute.



298
299
300
301
302
303
# File 'lib/sequel/serializer/xml_serializer.rb', line 298

def initialize(name, record)
  @name, @record = name, record

  @type  = compute_type
  @value = compute_value
end

Instance Attribute Details

#nameObject (readonly)

:nodoc:



296
297
298
# File 'lib/sequel/serializer/xml_serializer.rb', line 296

def name
  @name
end

#typeObject (readonly)

:nodoc:



296
297
298
# File 'lib/sequel/serializer/xml_serializer.rb', line 296

def type
  @type
end

#valueObject (readonly)

:nodoc:



296
297
298
# File 'lib/sequel/serializer/xml_serializer.rb', line 296

def value
  @value
end

Instance Method Details

#decorations(include_types = true, include_nils = true) ⇒ Object

I added include_nils option, which rails will in rails 3 anyway



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
# File 'lib/sequel/serializer/xml_serializer.rb', line 319

def decorations(include_types = true, include_nils = true)
  decorations = {}

  if type == :binary
    decorations[:encoding] = 'base64'
  end

  if include_types && type != :string
    decorations[:type] = type
  end

  if include_nils && value.nil?
    decorations[:nil] = true
  end

  decorations
end

#needs_encoding?Boolean

There is a significant speed improvement if the value does not need to be escaped, as tag! 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 tag! method. It definitely makes no sense to Base64 encode the value and then give it to tag!, since that just adds additional overhead.

Returns:

  • (Boolean)


314
315
316
# File 'lib/sequel/serializer/xml_serializer.rb', line 314

def needs_encoding?
  ![ :binary, :date, :datetime, :boolean, :float, :integer ].include?(type)
end