Class: NeptuneCoffee::SimpleDirectoryStructure
- Inherits:
-
Object
- Object
- NeptuneCoffee::SimpleDirectoryStructure
- Defined in:
- lib/neptune_coffee/simple_directory_structure.rb
Instance Attribute Summary collapse
-
#directories ⇒ Object
Returns the value of attribute directories.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
- #add(path, subdir) ⇒ Object
- #add_all(path = @root) ⇒ Object
- #all ⇒ Object
-
#initialize(root) ⇒ SimpleDirectoryStructure
constructor
A new instance of SimpleDirectoryStructure.
- #length ⇒ Object
- #subdirs(path = @root) ⇒ Object
- #valid_path(path) ⇒ Object
Constructor Details
#initialize(root) ⇒ SimpleDirectoryStructure
Returns a new instance of SimpleDirectoryStructure.
5 6 7 8 |
# File 'lib/neptune_coffee/simple_directory_structure.rb', line 5 def initialize root @root = Pathname.new root @directories={@root => []} end |
Instance Attribute Details
#directories ⇒ Object
Returns the value of attribute directories.
4 5 6 |
# File 'lib/neptune_coffee/simple_directory_structure.rb', line 4 def directories @directories end |
#root ⇒ Object
Returns the value of attribute root.
4 5 6 |
# File 'lib/neptune_coffee/simple_directory_structure.rb', line 4 def root @root end |
Instance Method Details
#add(path, subdir) ⇒ Object
22 23 24 25 26 27 28 |
# 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) ⇒ Object
38 39 40 41 42 43 44 |
# 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 ⇒ Object
30 31 32 |
# File 'lib/neptune_coffee/simple_directory_structure.rb', line 30 def all @directories.keys end |
#length ⇒ Object
10 |
# File 'lib/neptune_coffee/simple_directory_structure.rb', line 10 def length; @directories.length; end |
#subdirs(path = @root) ⇒ Object
34 35 36 |
# File 'lib/neptune_coffee/simple_directory_structure.rb', line 34 def subdirs path = @root @directories[valid_path(path)] end |
#valid_path(path) ⇒ Object
12 13 14 15 16 17 18 19 20 |
# 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 |