Class: Representable::XML::PropertyBinding
- Inherits:
-
Binding
- Object
- Binding
- Representable::XML::PropertyBinding
show all
- Defined in:
- lib/representable/bindings/xml_bindings.rb
Instance Attribute Summary
Attributes inherited from Binding
#definition
Instance Method Summary
collapse
Methods inherited from Binding
#deserialize, #serialize
Constructor Details
Returns a new instance of PropertyBinding.
27
28
29
30
|
# File 'lib/representable/bindings/xml_bindings.rb', line 27
def initialize(definition)
super
extend ObjectBinding if definition.typed?
end
|
Instance Method Details
#deserialize_from(nodes) ⇒ Object
64
65
66
|
# File 'lib/representable/bindings/xml_bindings.rb', line 64
def deserialize_from(nodes)
deserialize_node(nodes.first)
end
|
#deserialize_node(node) ⇒ Object
DISCUSS: rename to #read_from ?
69
70
71
|
# File 'lib/representable/bindings/xml_bindings.rb', line 69
def deserialize_node(node)
deserialize(node.content)
end
|
#read(node) ⇒ Object
42
43
44
45
46
47
48
49
50
|
# File 'lib/representable/bindings/xml_bindings.rb', line 42
def read(node)
selector = "./#{xpath}"
selector = "./#{definition.options[:wrap]}/#{xpath}" if definition.options[:wrap]
nodes = node.search(selector)
return FragmentNotFound if nodes.size == 0
deserialize_from(nodes)
end
|
#serialize_for(value, parent) ⇒ Object
Creates wrapped node for the property.
53
54
55
56
57
|
# File 'lib/representable/bindings/xml_bindings.rb', line 53
def serialize_for(value, parent)
node = node_for(parent, definition.from)
serialize_node(node, value)
end
|
#serialize_node(node, value) ⇒ Object
59
60
61
62
|
# File 'lib/representable/bindings/xml_bindings.rb', line 59
def serialize_node(node, value)
node.content = serialize(value)
node
end
|
#write(parent, value) ⇒ Object
32
33
34
35
36
37
38
39
40
|
# File 'lib/representable/bindings/xml_bindings.rb', line 32
def write(parent, value)
wrap_node = parent
if wrap = definition.options[:wrap]
parent << wrap_node = node_for(parent, wrap)
end
wrap_node << serialize_for(value, parent)
end
|