Class: ACLS::Tree
- Inherits:
-
Object
- Object
- ACLS::Tree
- Defined in:
- lib/acls/tree.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#directory ⇒ Object
Returns the value of attribute directory.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
-
#source ⇒ Object
Returns the value of attribute source.
Instance Method Summary collapse
-
#find(name) ⇒ Object
Find the first child with a given name, including the calling node in the search.
-
#initialize(parent, name, directory, source = nil) ⇒ Tree
constructor
A new instance of Tree.
- #make_child(name, directory, source = nil) ⇒ Object
-
#path ⇒ Object
If a source file is specified, returns the path to the source file.
- #to_s(level = 0) ⇒ Object
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
#children ⇒ Object
Returns the value of attribute children.
3 4 5 |
# File 'lib/acls/tree.rb', line 3 def children @children end |
#directory ⇒ Object
Returns the value of attribute directory.
3 4 5 |
# File 'lib/acls/tree.rb', line 3 def directory @directory end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/acls/tree.rb', line 3 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent.
3 4 5 |
# File 'lib/acls/tree.rb', line 3 def parent @parent end |
#source ⇒ Object
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 |
#path ⇒ Object
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 |