Class: Fhlow::RootNode

Inherits:
Node
  • Object
show all
Defined in:
lib/module_fhlow/rootnode.rb

Overview

This class represents the root directory of one fhlow environment and is therefore the main Node with @nodelevel = 0.

Instance Attribute Summary

Attributes inherited from Node

#conf, #name, #prefix

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Node

#fetchDependencies, #getLeaf, #printMe

Constructor Details

#initialize(_defaultconf, _log, _pen, _path = RootNode.detectFhlowRootDir) ⇒ RootNode

Initializes the memebers and the LeafFactory.

_log

A reference to a Log object.

_pen

A reference to a Pen output object.

Raises:



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/module_fhlow/rootnode.rb', line 38

def initialize(_defaultconf, _log, _pen, _path=RootNode.detectFhlowRootDir)
    
    @path = _path    
    
    # don't do anything if _path is nil
    raise FhlowException.new(self.class), "Couldn't detect the fhlow root directory!" if _path.nil?
    raise FhlowException.new(self.class), "You have to provide a default configuration object!" if !_defaultconf.instance_of?(Config::Config)
    

    # load all the leaf classes
    LeafFactory.load(@path+"/flw/core/lib/module_fhlow/leafs/")

    super("", "", self, 0, _log, _pen, _defaultconf)

    @nodes.each_value { |node| node.fetchDependencies() }

end

Class Method Details

.detectFhlowRootDir(_dir = Dir.pwd) ⇒ Object

Tries to detect the root directory of the actual fhlow root directory by parsing the string provided by ‘Dir.pwd’.

_dir

The directory that will be used to find the fhlow root directory.

Raises:



89
90
91
92
93
94
95
96
97
# File 'lib/module_fhlow/rootnode.rb', line 89

def RootNode.detectFhlowRootDir(_dir=Dir.pwd)
    raise FhlowException.new(self.class), "Couldn't detect the fhlow root directory!" if _dir==""
    if Dir.entries(_dir).include?("flw")
        return _dir+"/"
    else
        return detectFhlowRootDir(_dir.gsub(/(.*)\/\w*[\/]*/,'\1'))
    end

end

Instance Method Details

#getActualLeaf(_dir = Dir.pwd) ⇒ Object

Raises:



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/module_fhlow/rootnode.rb', line 56

def getActualLeaf(_dir=Dir.pwd)
    raise FhlowException.new(self.class), "couldn't detect the actual child!" if _dir =~ /.*\/flw\/.*/
    
    ofp = _dir.gsub(@path,"").split("/")
    
    prefixfound = false
    
    begin

        @conf["fhlow"]["LeafPrefixes"].reverse.each do |prefixlevel|
            prefixlevel.split(",").each do |prefix|
                prefixfound = true if ofp[-1] =~ /#{prefix}.*/
                return getLeaf(ofp) if prefixfound && ofp.length > 1
                raise FhlowException.new(self.class), "couldn't detect the actual child!" if ofp.length < 2
            end
        end

        ofp.delete_at(-1) if !prefixfound

    end until prefixfound == true

end

#getPathObject

Returns the path to the fhlow root directory.



81
82
83
# File 'lib/module_fhlow/rootnode.rb', line 81

def getPath
    @path
end