Class: Tilia::Dav::SimpleCollection
- Inherits:
-
Collection
- Object
- Node
- Collection
- Tilia::Dav::SimpleCollection
- Defined in:
- lib/tilia/dav/simple_collection.rb
Overview
SimpleCollection
The SimpleCollection is used to quickly setup static directory structures. Just create the object with a proper name, and add children to use it.
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns a list of children for this collection.
-
#name ⇒ Object
Returns the name of the collection.
Instance Method Summary collapse
-
#add_child(child) ⇒ Object
Adds a new childnode to this collection.
-
#child(name) ⇒ Object
Returns a child object, by its name.
-
#initialize(name, children = []) ⇒ SimpleCollection
constructor
Creates this node.
Methods inherited from Collection
#child_exists, #create_directory, #create_file
Methods included from ICollection
#child_exists, #create_directory, #create_file
Methods included from INode
Methods inherited from Node
Constructor Details
#initialize(name, children = []) ⇒ SimpleCollection
Creates this node
The name of the node must be passed, child nodes can also be passed. This nodes must be instances of INode
25 26 27 28 29 30 31 32 |
# File 'lib/tilia/dav/simple_collection.rb', line 25 def initialize(name, children = []) @name = name @children = {} children.each do |child| fail(Exception, 'Only instances of Sabre\DAV\INode are allowed to be passed in the children argument') unless child.is_a? INode add_child(child) end end |
Instance Attribute Details
#children ⇒ Object
Returns a list of children for this collection
11 12 13 |
# File 'lib/tilia/dav/simple_collection.rb', line 11 def children @children end |
#name ⇒ Object
Returns the name of the collection
16 17 18 |
# File 'lib/tilia/dav/simple_collection.rb', line 16 def name @name end |
Instance Method Details
#add_child(child) ⇒ Object
Adds a new childnode to this collection
38 39 40 |
# File 'lib/tilia/dav/simple_collection.rb', line 38 def add_child(child) @children[child.name] = child end |
#child(name) ⇒ Object
Returns a child object, by its name.
This method makes use of the getChildren method to grab all the child nodes, and compares the name. Generally its wise to override this, as this can usually be optimized
This method must throw SabreDAVExceptionNotFound if the node does not exist.
58 59 60 61 |
# File 'lib/tilia/dav/simple_collection.rb', line 58 def child(name) return @children[name] if @children.key?(name) fail Exception::NotFound, "File not found: #{name} in '#{name}'" end |