Class: Representable::XML::PropertyBinding
- Inherits:
-
Binding
- Object
- SimpleDelegator
- Binding
- Representable::XML::PropertyBinding
show all
- Defined in:
- lib/representable/bindings/xml_bindings.rb
Instance Attribute Summary
Attributes inherited from Binding
#represented, #user_options
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Binding
build, #definition, #deserialize, #get, #read_fragment, #read_fragment_for, #serialize, #set, #write_fragment, #write_fragment_for
Constructor Details
Returns a new instance of PropertyBinding.
35
36
37
38
|
# File 'lib/representable/bindings/xml_bindings.rb', line 35
def initialize(*args)
super
extend ObjectBinding if typed?
end
|
Class Method Details
.build_for(definition, *args) ⇒ Object
27
28
29
30
31
32
33
|
# File 'lib/representable/bindings/xml_bindings.rb', line 27
def self.build_for(definition, *args)
return CollectionBinding.new(definition, *args) if definition.array?
return HashBinding.new(definition, *args) if definition.hash? and not definition.options[:use_attributes]
return AttributeHashBinding.new(definition, *args) if definition.hash? and definition.options[:use_attributes]
return AttributeBinding.new(definition, *args) if definition.attribute
new(definition, *args)
end
|
Instance Method Details
#deserialize_from(nodes) ⇒ Object
69
70
71
|
# File 'lib/representable/bindings/xml_bindings.rb', line 69
def deserialize_from(nodes)
deserialize_node(nodes.first)
end
|
#deserialize_node(node) ⇒ Object
DISCUSS: rename to #read_from ?
74
75
76
|
# File 'lib/representable/bindings/xml_bindings.rb', line 74
def deserialize_node(node)
deserialize(node.content)
end
|
#read(node) ⇒ Object
50
51
52
53
54
55
|
# File 'lib/representable/bindings/xml_bindings.rb', line 50
def read(node)
nodes = find_nodes(node)
return FragmentNotFound if nodes.size == 0
deserialize_from(nodes)
end
|
#serialize_for(value, parent) ⇒ Object
Creates wrapped node for the property.
58
59
60
61
62
|
# File 'lib/representable/bindings/xml_bindings.rb', line 58
def serialize_for(value, parent)
node = node_for(parent, from)
serialize_node(node, value)
end
|
#serialize_node(node, value) ⇒ Object
64
65
66
67
|
# File 'lib/representable/bindings/xml_bindings.rb', line 64
def serialize_node(node, value)
node.content = serialize(value)
node
end
|
#write(parent, value) ⇒ Object
40
41
42
43
44
45
46
47
48
|
# File 'lib/representable/bindings/xml_bindings.rb', line 40
def write(parent, value)
wrap_node = parent
if wrap = options[:wrap]
parent << wrap_node = node_for(parent, wrap)
end
wrap_node << serialize_for(value, parent)
end
|