Class: Tilia::DavAcl::Xml::Property::CurrentUserPrivilegeSet
- Includes:
- Tilia::Dav::Browser::HtmlOutput, Xml::Element
- Defined in:
- lib/tilia/dav_acl/xml/property/current_user_privilege_set.rb
Overview
CurrentUserPrivilegeSet
This class represents the current-user-privilege-set property. When requested, it contain all the privileges a user has on a specific node.
Class Method Summary collapse
-
.xml_deserialize(reader) ⇒ Object
The deserialize method is called during xml parsing.
Instance Method Summary collapse
-
#has(privilege_name) ⇒ Object
Returns true or false, whether the specified principal appears in the list.
-
#initialize(privileges) ⇒ CurrentUserPrivilegeSet
constructor
Creates the object.
-
#to_html(html) ⇒ Object
Generate html representation for this value.
-
#value ⇒ Object
Returns the list of privileges.
-
#xml_serialize(writer) ⇒ Object
The xmlSerialize metod is called during xml writing.
Constructor Details
#initialize(privileges) ⇒ CurrentUserPrivilegeSet
Creates the object
Pass the privileges in clark-notation
27 28 29 |
# File 'lib/tilia/dav_acl/xml/property/current_user_privilege_set.rb', line 27 def initialize(privileges) @privileges = privileges 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.
91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/tilia/dav_acl/xml/property/current_user_privilege_set.rb', line 91 def self.xml_deserialize(reader) result = [] tree = reader.parse_inner_tree('{DAV:}privilege' => Tilia::Xml::Element::Elements) tree.each do |element| next unless element['name'] == '{DAV:}privilege' result << element['value'][0] end new(result) end |
Instance Method Details
#has(privilege_name) ⇒ Object
Returns true or false, whether the specified principal appears in the list.
61 62 63 |
# File 'lib/tilia/dav_acl/xml/property/current_user_privilege_set.rb', line 61 def has(privilege_name) @privileges.include?(privilege_name) end |
#to_html(html) ⇒ Object
Generate html representation for this value.
The html output is 100% trusted, and no effort is being made to sanitize it. It’s up to the implementor to sanitize user provided values.
The output must be in UTF-8.
The baseUri parameter is a url to the root of the application, and can be used to construct local links.
115 116 117 118 119 120 |
# File 'lib/tilia/dav_acl/xml/property/current_user_privilege_set.rb', line 115 def to_html(html) props = @privileges.map do |property| html.xml_name(property) end props.join(', ') end |
#value ⇒ Object
Returns the list of privileges.
68 69 70 |
# File 'lib/tilia/dav_acl/xml/property/current_user_privilege_set.rb', line 68 def value @privileges end |
#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.
48 49 50 51 52 53 54 |
# File 'lib/tilia/dav_acl/xml/property/current_user_privilege_set.rb', line 48 def xml_serialize(writer) @privileges.each do |priv_name| writer.start_element('{DAV:}privilege') writer.write_element(priv_name) writer.end_element end end |