Class: Tilia::Dav::SimpleCollection

Inherits:
Collection show all
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

Instance Method Summary collapse

Methods inherited from Collection

#child_exists, #create_directory, #create_file

Methods included from ICollection

#child_exists, #create_directory, #create_file

Methods included from INode

#delete, #last_modified

Methods inherited from Node

#delete, #last_modified

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

Parameters:

  • string

    name

  • INode[]

    children



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

#childrenObject

Returns a list of children for this collection

Returns:

  • INode[]



11
12
13
# File 'lib/tilia/dav/simple_collection.rb', line 11

def children
  @children
end

#nameObject

Returns the name of the collection

Returns:

  • string



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

Parameters:

  • INode

    child

Returns:

  • void



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.

Parameters:

  • string

    name

Returns:

  • INode



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