class NeptuneCoffee::SimpleDirectoryStructure
Attributes
directories[RW]
root[RW]
Public Class Methods
new(root)
click to toggle source
# File lib/neptune_coffee/simple_directory_structure.rb, line 5 def initialize root @root = Pathname.new root @directories={@root => []} end
Public Instance Methods
add(path, subdir)
click to toggle source
# File lib/neptune_coffee/simple_directory_structure.rb, line 22 def add path, subdir path = valid_path path subdir_path = path + subdir @directories[subdir_path] = [] @directories[path] << subdir_path subdir_path end
add_all(path = @root)
click to toggle source
# File lib/neptune_coffee/simple_directory_structure.rb, line 38 def add_all path = @root valid_path(path).children.each do |c| next unless c.directory? add path, c.basename add_all c end end
all()
click to toggle source
# File lib/neptune_coffee/simple_directory_structure.rb, line 30 def all @directories.keys end
length()
click to toggle source
# File lib/neptune_coffee/simple_directory_structure.rb, line 10 def length; @directories.length; end
subdirs(path = @root)
click to toggle source
# File lib/neptune_coffee/simple_directory_structure.rb, line 34 def subdirs path = @root @directories[valid_path(path)] end
valid_path(path)
click to toggle source
# File lib/neptune_coffee/simple_directory_structure.rb, line 12 def valid_path path path = case path when Pathname then path when String then Pathname.new path else raise "invalid path object type: #{path.class}" end raise "path #{path.to_s.inspect} has not been added" unless @directories[path] path end