Class: Representable::XML::Binding

Inherits:
Binding
  • Object
show all
Defined in:
lib/representable/xml/binding.rb

Direct Known Subclasses

Attribute, Collection, Content

Defined Under Namespace

Classes: Attribute, AttributeHash, Collection, Content, Hash

Instance Attribute Summary

Attributes inherited from Binding

#cached_representer, #getter, #name, #setter

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Binding

#[], build, #default_for, #initialize, #skipable_empty_value?

Methods included from Binding::Factories

#collect_for, #default_parse_fragment_functions, #default_parse_init_functions, #default_post_functions, #default_render_fragment_functions, #default_render_init_functions, #parse_functions, #pipeline_for, #render_functions

Methods included from Binding::EvaluateOption

#evaluate_option

Methods included from Binding::Deprecatable

#compile_fragment, #uncompile_fragment

Constructor Details

This class inherits a constructor from Representable::Binding

Class Method Details

.build_for(definition) ⇒ Object



7
8
9
10
11
12
13
14
# File 'lib/representable/xml/binding.rb', line 7

def self.build_for(definition)
  return Collection.new(definition)      if definition.array?
  return Hash.new(definition)            if definition.hash? and not definition[:use_attributes] # FIXME: hate this.
  return AttributeHash.new(definition)   if definition.hash? and definition[:use_attributes]
  return Attribute.new(definition)       if definition[:attribute]
  return Content.new(definition)         if definition[:content]
  new(definition)
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_methodObject



55
56
57
# File 'lib/representable/xml/binding.rb', line 55

def deserialize_method
  :from_node
end

#read(node, as) ⇒ Object



26
27
28
29
30
31
# File 'lib/representable/xml/binding.rb', line 26

def read(node, as)
  nodes = find_nodes(node, as)
  return FragmentNotFound if nodes.size == 0 # TODO: write dedicated test!

  deserialize_from(nodes)
end

#serialize_for(value, parent, as) ⇒ Object

Creates wrapped node for the property.



34
35
36
37
# File 'lib/representable/xml/binding.rb', line 34

def serialize_for(value, parent, as)
  node = node_for(parent, as)
  serialize_node(node, value)
end

#serialize_methodObject

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, as) ⇒ Object



16
17
18
19
20
21
22
23
24
# File 'lib/representable/xml/binding.rb', line 16

def write(parent, fragments, as)
  wrap_node = parent

  if wrap = self[:wrap]
    parent << wrap_node = node_for(parent, wrap)
  end

  wrap_node << serialize_for(fragments, parent, as)
end