Class: Tilia::Dav::Xml::Request::PropPatch
- Includes:
- Xml::Element
- Defined in:
- lib/tilia/dav/xml/request/prop_patch.rb
Overview
WebDAV PROPPATCH request parser.
This class parses the DAV:propertyupdate request, as defined in:
Instance Attribute Summary collapse
-
#properties ⇒ Object
The list of properties that will be updated and removed.
Class Method Summary collapse
-
.xml_deserialize(reader) ⇒ Object
The deserialize method is called during xml parsing.
Instance Method Summary collapse
-
#initialize ⇒ PropPatch
constructor
A new instance of PropPatch.
-
#xml_serialize(writer) ⇒ Object
The xmlSerialize metod is called during xml writing.
Constructor Details
#initialize ⇒ PropPatch
Returns a new instance of PropPatch.
94 95 96 |
# File 'lib/tilia/dav/xml/request/prop_patch.rb', line 94 def initialize @properties = {} end |
Instance Attribute Details
#properties ⇒ Object
The list of properties that will be updated and removed.
If a property will be removed, it’s value will be set to null.
18 19 20 |
# File 'lib/tilia/dav/xml/request/prop_patch.rb', line 18 def properties @properties end |
Class Method Details
.xml_deserialize(reader) ⇒ Object
The deserialize method is called during xml parsing.
This method is called statictly, this is because in theory this method may be used as a type of constructor, or factory method.
Often you want to return an instance of the current class, but you are free to return other data as well.
You are responsible for advancing the reader to the next element. Not doing anything will result in a never-ending loop.
If you just want to skip parsing for this element altogether, you can just call reader.next
reader.parse_inner_tree will parse the entire sub-tree, and advance to the next element.
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/tilia/dav/xml/request/prop_patch.rb', line 70 def self.xml_deserialize(reader) instance = new element_map = reader.element_map element_map['{DAV:}prop'] = Tilia::Dav::Xml::Element::Prop element_map['{DAV:}set'] = Tilia::Xml::Element::KeyValue element_map['{DAV:}remove'] = Tilia::Xml::Element::KeyValue elems = reader.parse_inner_tree(element_map) elems.each do |elem| if elem['name'] == '{DAV:}set' instance.properties.merge! elem['value']['{DAV:}prop'] elsif elem['name'] == '{DAV:}remove' # Ensuring there are no values. elem['value']['{DAV:}prop'].each do |remove, _value| instance.properties[remove] = nil end end end instance end |
Instance Method Details
#xml_serialize(writer) ⇒ Object
The xmlSerialize metod is called during xml writing.
Use the writer argument to write its own xml serialization.
An important note: do not create a parent element. Any element implementing XmlSerializble should only ever write what’s considered its ‘inner xml’.
The parent of the current element is responsible for writing a containing element.
This allows serializers to be re-used for different element names.
If you are opening new elements, you must also close them again.
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/tilia/dav/xml/request/prop_patch.rb', line 37 def xml_serialize(writer) properties.each do |property_name, property_value| if property_value.nil? writer.start_element('{DAV:}remove') writer.write('{DAV:}prop' => { property_name => property_value }) writer.end_element else writer.start_element('{DAV:}set') writer.write('{DAV:}prop' => { property_name => property_value }) writer.end_element end end end |