Class: ACLS::Tree

Inherits:
Object
  • Object
show all
Defined in:
lib/acls/tree.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, name, directory, source = nil) ⇒ Tree

Returns a new instance of Tree.



5
6
7
8
9
10
11
# File 'lib/acls/tree.rb', line 5

def initialize(parent, name, directory, source=nil)
  @parent = parent
  @name = name
  @directory = directory
  @source = source
  @children = []
end

Instance Attribute Details

#childrenObject

Returns the value of attribute children.



3
4
5
# File 'lib/acls/tree.rb', line 3

def children
  @children
end

#directoryObject

Returns the value of attribute directory.



3
4
5
# File 'lib/acls/tree.rb', line 3

def directory
  @directory
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/acls/tree.rb', line 3

def name
  @name
end

#parentObject

Returns the value of attribute parent.



3
4
5
# File 'lib/acls/tree.rb', line 3

def parent
  @parent
end

#sourceObject

Returns the value of attribute source.



3
4
5
# File 'lib/acls/tree.rb', line 3

def source
  @source
end

Instance Method Details

#find(name) ⇒ Object

Find the first child with a given name, including the calling node in the search.



26
27
28
29
# File 'lib/acls/tree.rb', line 26

def find(name)
  return self if @name == name
  @children.find { |child| child.find(name) }
end

#make_child(name, directory, source = nil) ⇒ Object



13
14
15
16
17
# File 'lib/acls/tree.rb', line 13

def make_child(name, directory, source=nil)
  child = Tree.new(self, name, directory, source)
  @children << child
  child
end

#pathObject

If a source file is specified, returns the path to the source file.



20
21
22
# File 'lib/acls/tree.rb', line 20

def path
  @source || @directory
end

#to_s(level = 0) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/acls/tree.rb', line 31

def to_s(level=0)
  tab = '**' * 2 * level
  "\#{tab}     level: \#{level}\n\#{tab}      name: \#{@name}\n\#{tab}    source: \#{@source}\n\#{tab} directory: \#{@directory}\n\#{tab}  children => [\n\#{@children.map { |child| child.to_s(level+1) }.join}\n\#{tab}  ]\n"
end