Class: CouchFoo::XmlSerializer::Attribute
- Inherits:
-
Object
- Object
- CouchFoo::XmlSerializer::Attribute
- Defined in:
- lib/couch_foo/serializers/xml_serializer.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#value ⇒ Object
readonly
Returns the value of attribute value.
Instance Method Summary collapse
- #decorations(include_types = true) ⇒ Object
-
#initialize(name, record) ⇒ Attribute
constructor
A new instance of Attribute.
-
#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.
Constructor Details
#initialize(name, record) ⇒ Attribute
Returns a new instance of Attribute.
269 270 271 272 273 274 275 |
# File 'lib/couch_foo/serializers/xml_serializer.rb', line 269 def initialize(name, record) @name, @record = name, record @name = name.gsub("_", "") if name[0] == '_'[0] # _id and _rev are not valid XML tags @type = compute_type @value = compute_value end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
267 268 269 |
# File 'lib/couch_foo/serializers/xml_serializer.rb', line 267 def name @name end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
267 268 269 |
# File 'lib/couch_foo/serializers/xml_serializer.rb', line 267 def type @type end |
#value ⇒ Object (readonly)
Returns the value of attribute value.
267 268 269 |
# File 'lib/couch_foo/serializers/xml_serializer.rb', line 267 def value @value end |
Instance Method Details
#decorations(include_types = true) ⇒ Object
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/couch_foo/serializers/xml_serializer.rb', line 290 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 |
#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.
286 287 288 |
# File 'lib/couch_foo/serializers/xml_serializer.rb', line 286 def needs_encoding? ![ :binary, :date, :datetime, :boolean, :float, :integer ].include?(type) end |