Class: DirTree
- Inherits:
-
Object
- Object
- DirTree
- Defined in:
- lib/dir_tree.rb
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
Class Method Summary collapse
Instance Method Summary collapse
- #each_node(&blk) ⇒ Object
-
#initialize(base) ⇒ DirTree
constructor
A new instance of DirTree.
Constructor Details
#initialize(base) ⇒ DirTree
Returns a new instance of DirTree.
9 10 11 |
# File 'lib/dir_tree.rb', line 9 def initialize(base) self.base = base end |
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base.
7 8 9 |
# File 'lib/dir_tree.rb', line 7 def base @base end |
Class Method Details
.link(src, dst, options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/dir_tree.rb', line 18 def self.link src, dst, ={} copy = [:copy] || [] FileUtils.mkdir_p dst DirTree.new(src).each_node do |base, path| src_path = File.join(base, path) dst_path = File.join(dst, path) if File.directory?(src_path) FileUtils.mkdir dst_path elsif copy.include?(path) FileUtils.cp src_path, dst_path else FileUtils.link src_path, dst_path end end end |
Instance Method Details
#each_node(&blk) ⇒ Object
13 14 15 16 |
# File 'lib/dir_tree.rb', line 13 def each_node(&blk) @base = Dir.new(@base) unless @base.kind_of?(Dir) recurse('', &blk) end |