Class: Rabal::DirectoryTree

Inherits:
ActionTree show all
Defined in:
lib/rabal/directory_tree.rb

Overview

A directory that is to be created or traversed. When this Tree is invoked it is assumed that the current working directory is the parent of the directory this DirectoryTree represents.

Direct Known Subclasses

PluginTree, ProjectTree

Instance Attribute Summary collapse

Attributes inherited from Tree

#children, #name, #parameters, #parent

Instance Method Summary collapse

Methods inherited from ActionTree

#process

Methods inherited from Tree

#<<, #add_at_path, #current_path, #depth, #each, #find_subtree, #has_subtree?, #is_leaf?, #is_root?, #method_missing, #post_add, #root, #size, #tree_at_path, #walk

Constructor Details

#initialize(name) ⇒ DirectoryTree

Create a DirectoryTree based up a name, or another directory. Only the last portion of the directory is used. That is File.basename is called upon name.



24
25
26
27
28
# File 'lib/rabal/directory_tree.rb', line 24

def initialize(name)
    super(name)
    @dir_name = File.basename(name)
    @parent_dir = nil
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Rabal::Tree

Instance Attribute Details

#dir_nameObject

basename of the directory this Tree represents



15
16
17
# File 'lib/rabal/directory_tree.rb', line 15

def dir_name
  @dir_name
end

#parent_dirObject

the File system directory that is the parent of the directory this DirectoryTree represents.



19
20
21
# File 'lib/rabal/directory_tree.rb', line 19

def parent_dir
  @parent_dir
end

Instance Method Details

#actionObject

change into the directory



46
47
48
49
# File 'lib/rabal/directory_tree.rb', line 46

def action
    debug("entering #{dir_name}")
    Dir.chdir(dir_name)
end

#after_actionObject

change back to the parent directory



54
55
56
57
# File 'lib/rabal/directory_tree.rb', line 54

def after_action
    debug("leaving #{dir_name}")
    Dir.chdir(parent_dir)
end

#before_actionObject

Make the directory if it doesn’t exist



33
34
35
36
37
38
39
40
41
# File 'lib/rabal/directory_tree.rb', line 33

def before_action
    @parent_dir = Dir.pwd
    if not File.directory?(dir_name) then
        info("creating #{dir_name}")
        Dir.mkdir(dir_name)
    else
        debug("skipping #{dir_name} - already exists")
    end
end