Class: ActiveModel::Serializers::Xml::Serializer::Attribute

Inherits:
Object
  • Object
show all
Defined in:
activemodel/lib/active_model/serializers/xml.rb

Overview

:nodoc:

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Attribute) initialize(name, serializable, raw_value = nil)



18
19
20
21
22
23
# File 'activemodel/lib/active_model/serializers/xml.rb', line 18

def initialize(name, serializable, raw_value=nil)
  @name, @serializable = name, serializable
  raw_value = raw_value.in_time_zone if raw_value.respond_to?(:in_time_zone)
  @value = raw_value || @serializable.send(name)
  @type  = compute_type
end

Instance Attribute Details

- (Object) name (readonly)

Returns the value of attribute name



16
17
18
# File 'activemodel/lib/active_model/serializers/xml.rb', line 16

def name
  @name
end

- (Object) type (readonly)

Returns the value of attribute type



16
17
18
# File 'activemodel/lib/active_model/serializers/xml.rb', line 16

def type
  @type
end

- (Object) value (readonly)

Returns the value of attribute value



16
17
18
# File 'activemodel/lib/active_model/serializers/xml.rb', line 16

def value
  @value
end

Instance Method Details

- (Object) decorations



25
26
27
28
29
30
31
# File 'activemodel/lib/active_model/serializers/xml.rb', line 25

def decorations
  decorations = {}
  decorations[:encoding] = 'base64' if type == :binary
  decorations[:type] = (type == :string) ? nil : type
  decorations[:nil] = true if value.nil?
  decorations
end