Class: Representable::XML::PropertyBinding
- Includes:
- Binding::Object
- Defined in:
- lib/representable/bindings/xml_bindings.rb
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from Binding
Class Method Summary collapse
Instance Method Summary collapse
- #deserialize_from(nodes) ⇒ Object
- #deserialize_method ⇒ Object
- #read(node) ⇒ Object
-
#serialize_for(value, parent) ⇒ Object
Creates wrapped node for the property.
-
#serialize_method ⇒ Object
DISCUSS: why is this public?.
- #serialize_node(node, value) ⇒ Object
- #write(parent, value) ⇒ Object
Methods included from Binding::Object
#create_object, #deserialize, #serialize
Methods inherited from Binding
#as, build, #compile_fragment, #get, #initialize, #read_fragment, #read_fragment_for, #representer_module_for, #set, #uncompile_fragment, #write_fragment, #write_fragment_for
Constructor Details
This class inherits a constructor from Representable::Binding
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Representable::Binding
Class Method Details
.build_for(definition, *args) ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/representable/bindings/xml_bindings.rb', line 9 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] return ContentBinding.new(definition, *args) if definition[:content] new(definition, *args) end |
Instance Method Details
#deserialize_from(nodes) ⇒ Object
49 50 51 52 |
# File 'lib/representable/bindings/xml_bindings.rb', line 49 def deserialize_from(nodes) content_for deserialize(nodes.first) #deserialize(nodes.first) end |
#deserialize_method ⇒ Object
59 60 61 |
# File 'lib/representable/bindings/xml_bindings.rb', line 59 def deserialize_method :from_node end |
#read(node) ⇒ Object
28 29 30 31 32 33 |
# File 'lib/representable/bindings/xml_bindings.rb', line 28 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.
36 37 38 39 40 |
# File 'lib/representable/bindings/xml_bindings.rb', line 36 def serialize_for(value, parent) #def serialize_for(value, parent, tag_name=definition.from) node = node_for(parent, as) serialize_node(node, value) end |
#serialize_method ⇒ Object
DISCUSS: why is this public?
55 56 57 |
# File 'lib/representable/bindings/xml_bindings.rb', line 55 def serialize_method :to_node end |
#serialize_node(node, value) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/representable/bindings/xml_bindings.rb', line 42 def serialize_node(node, value) return serialize(value) if typed? node.content = serialize(value) node end |
#write(parent, value) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/representable/bindings/xml_bindings.rb', line 18 def write(parent, value) wrap_node = parent if wrap = self[:wrap] parent << wrap_node = node_for(parent, wrap) end wrap_node << serialize_for(value, parent) end |