Class: Redwood::FileNode
Constant Summary
Constants included from Redwood
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes inherited from Node
Class Method Summary collapse
-
.scandir(dir = Dir.pwd, tree = nil) ⇒ Object
Takes a path and scans the directory, creating a Redwood tree.
Instance Method Summary collapse
-
#initialize(name, parent = nil) ⇒ FileNode
constructor
A new instance of FileNode.
- #method_missing(method, *args, &block) ⇒ Object
-
#value ⇒ Object
Some information to store in the node.
Methods inherited from Node
#<<, #[], #add_child
Methods included from Redwood
#ancestors, #children, #depth, #descendants, #graft, #has_children?, #height, #leaf?, #only_child?, #parent, #prune, #root, #root?, #siblings, #unlink, #view, #walk
Constructor Details
#initialize(name, parent = nil) ⇒ FileNode
Returns a new instance of FileNode.
27 28 29 30 |
# File 'lib/redwood/filenode.rb', line 27 def initialize(name, parent=nil) super @path = File.(name) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/redwood/filenode.rb', line 37 def method_missing(method, *args, &block) if File.respond_to?(method) File.send method, path else super end end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
25 26 27 |
# File 'lib/redwood/filenode.rb', line 25 def path @path end |
Class Method Details
.scandir(dir = Dir.pwd, tree = nil) ⇒ Object
Takes a path and scans the directory, creating a Redwood tree.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/redwood/filenode.rb', line 9 def self.scandir(dir = Dir.pwd, tree=nil) node = tree ? tree : self.new(dir) if File.directory?(dir) Dir.foreach(dir) do |d| if File.directory?("#{dir}/#{d}") node << scandir("#{dir}/#{d}",tree) unless (d.eql?('..') || d.eql?('.')) else node.add_child("#{dir}/#{d}") end end else node.add_child(dir) end node end |
Instance Method Details
#value ⇒ Object
Some information to store in the node. Defaults to the basename of the file/directory
33 34 35 |
# File 'lib/redwood/filenode.rb', line 33 def value @value ||= basename end |