Class: Representable::XML::PropertyBinding
- Defined in:
- lib/representable/bindings/xml_bindings.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Binding
#lambda_context, #represented, #user_options
Class Method Summary collapse
Instance Method Summary collapse
- #deserialize_from(nodes) ⇒ Object
-
#deserialize_node(node) ⇒ Object
DISCUSS: rename to #read_from ?.
-
#initialize(*args) ⇒ PropertyBinding
constructor
A new instance of PropertyBinding.
- #read(node) ⇒ Object
-
#serialize_for(value, parent) ⇒ Object
Creates wrapped node for the property.
- #serialize_node(node, value) ⇒ Object
- #write(parent, value) ⇒ Object
Methods inherited from Binding
build, #compile_fragment, #deserialize, #get, #read_fragment, #read_fragment_for, #serialize, #set, #uncompile_fragment, #write_fragment, #write_fragment_for
Constructor Details
#initialize(*args) ⇒ PropertyBinding
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? # FIXME. 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.[:use_attributes] # FIXME: hate this. return AttributeHashBinding.new(definition, *args) if definition.hash? and definition.[: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 # TODO: write dedicated test! 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) #def serialize_for(value, parent, tag_name=definition.from) 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 = [:wrap] parent << wrap_node = node_for(parent, wrap) end wrap_node << serialize_for(value, parent) end |