Class: RestfulX::Serialization::FXMLSerializer::Attribute
- Inherits:
-
Object
- Object
- RestfulX::Serialization::FXMLSerializer::Attribute
- Defined in:
- lib/restfulx/rx_active_record.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary (collapse)
-
- (Object) name
readonly
Returns the value of attribute name.
-
- (Object) type
readonly
Returns the value of attribute type.
-
- (Object) value
readonly
Returns the value of attribute value.
Instance Method Summary (collapse)
- - (Object) decorations(include_types = true)
-
- (Attribute) initialize(name, record)
constructor
A new instance of Attribute.
-
- (Boolean) needs_encoding?
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
- (Attribute) initialize(name, record)
A new instance of Attribute
121 122 123 124 125 126 |
# File 'lib/restfulx/rx_active_record.rb', line 121 def initialize(name, record) @name, @record = name, record @type = compute_type @value = compute_value end |
Instance Attribute Details
- (Object) name (readonly)
Returns the value of attribute name
119 120 121 |
# File 'lib/restfulx/rx_active_record.rb', line 119 def name @name end |
- (Object) type (readonly)
Returns the value of attribute type
119 120 121 |
# File 'lib/restfulx/rx_active_record.rb', line 119 def type @type end |
- (Object) value (readonly)
Returns the value of attribute value
119 120 121 |
# File 'lib/restfulx/rx_active_record.rb', line 119 def value @value end |
Instance Method Details
- (Object) decorations(include_types = true)
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/restfulx/rx_active_record.rb', line 141 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 |
- (Boolean) needs_encoding?
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.
137 138 139 |
# File 'lib/restfulx/rx_active_record.rb', line 137 def needs_encoding? ![ :binary, :date, :datetime, :boolean, :float, :integer ].include?(type) end |