Class: Representable::XML::Binding
- Defined in:
- lib/representable/xml/binding.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Attribute, AttributeHash, Collection, Content, Hash
Instance Attribute Summary
Attributes inherited from Binding
#array, #cached_representer, #getter, #has_default, #name, #representable, #represented, #setter, #skip_filters, #typed, #user_options
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, fragments) ⇒ Object
Methods inherited from Binding
#[], #as, build, #compile_fragment, #default_for, #evaluate_option, #get, #initialize, #parse_filter, #read_fragment, #render_filter, #render_fragment, #representer_module_for, #set, #skipable_empty_value?, #uncompile_fragment, #update!, #write_fragment
Methods included from Binding::Factories
#deserializer, #deserializer_class, #populator, #populator_class, #serializer, #serializer_class
Constructor Details
This class inherits a constructor from Representable::Binding
Class Method Details
.build_for(definition, *args) ⇒ Object
7 8 9 10 11 12 13 14 |
# File 'lib/representable/xml/binding.rb', line 7 def self.build_for(definition, *args) return Collection.new(definition, *args) if definition.array? return Hash.new(definition, *args) if definition.hash? and not definition[:use_attributes] # FIXME: hate this. return AttributeHash.new(definition, *args) if definition.hash? and definition[:use_attributes] return Attribute.new(definition, *args) if definition[:attribute] return Content.new(definition, *args) if definition[:content] new(definition, *args) end |
Instance Method Details
#deserialize_from(nodes) ⇒ Object
46 47 48 |
# File 'lib/representable/xml/binding.rb', line 46 def deserialize_from(nodes) content_for(nodes.first) end |
#deserialize_method ⇒ Object
55 56 57 |
# File 'lib/representable/xml/binding.rb', line 55 def deserialize_method :from_node end |
#read(node) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/representable/xml/binding.rb', line 26 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.
34 35 36 37 |
# File 'lib/representable/xml/binding.rb', line 34 def serialize_for(value, parent) node = node_for(parent, as) serialize_node(node, value) end |
#serialize_method ⇒ Object
DISCUSS: why is this public?
51 52 53 |
# File 'lib/representable/xml/binding.rb', line 51 def serialize_method :to_node end |
#serialize_node(node, value) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/representable/xml/binding.rb', line 39 def serialize_node(node, value) return value if typed? node.content = value node end |
#write(parent, fragments) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/representable/xml/binding.rb', line 16 def write(parent, fragments) wrap_node = parent if wrap = self[:wrap] parent << wrap_node = node_for(parent, wrap) end wrap_node << serialize_for(fragments, parent) end |