Class: Ghq::Cache::Directory
- Inherits:
-
Struct
- Object
- Struct
- Ghq::Cache::Directory
- Defined in:
- lib/ghq/cache/directory.rb
Instance Attribute Summary collapse
-
#children ⇒ Object
Returns the value of attribute children.
-
#count ⇒ Object
Returns the value of attribute count.
-
#name ⇒ Object
Returns the value of attribute name.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #count_path(path) ⇒ Object
-
#initialize ⇒ Directory
constructor
A new instance of Directory.
- #path_from_root ⇒ Object
- #register_path(path) ⇒ Object
- #remove_path(path) ⇒ Object
- #root? ⇒ Boolean
Constructor Details
#initialize ⇒ Directory
Returns a new instance of Directory.
4 5 6 7 8 |
# File 'lib/ghq/cache/directory.rb', line 4 def initialize(*) super self.count ||= 0 self.children ||= [] end |
Instance Attribute Details
#children ⇒ Object
Returns the value of attribute children
3 4 5 |
# File 'lib/ghq/cache/directory.rb', line 3 def children @children end |
#count ⇒ Object
Returns the value of attribute count
3 4 5 |
# File 'lib/ghq/cache/directory.rb', line 3 def count @count end |
#name ⇒ Object
Returns the value of attribute name
3 4 5 |
# File 'lib/ghq/cache/directory.rb', line 3 def name @name end |
#parent ⇒ Object
Returns the value of attribute parent
3 4 5 |
# File 'lib/ghq/cache/directory.rb', line 3 def parent @parent end |
Instance Method Details
#count_path(path) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/ghq/cache/directory.rb', line 10 def count_path(path) abort "Path didn't matched to Directory" unless path =~ /^#{name}/ self.count += 1 relative_path = path.gsub(%r[^#{name}/?], '') return if relative_path.empty? child = create_or_find(relative_path.split('/').first) child.count_path(relative_path) end |
#path_from_root ⇒ Object
43 44 45 46 |
# File 'lib/ghq/cache/directory.rb', line 43 def path_from_root return name if parent.nil? || parent.root? File.join(parent.path_from_root, name) end |
#register_path(path) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/ghq/cache/directory.rb', line 21 def register_path(path) abort "Path didn't matched to Directory" unless path =~ /^#{name}/ relative_path = path.gsub(%r[^#{name}/?], '') return if relative_path.empty? child = create_or_find(relative_path.split('/').first) child.register_path(relative_path) end |
#remove_path(path) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/ghq/cache/directory.rb', line 31 def remove_path(path) relative_path = path.gsub(%r[^#{name}/?], '') return if relative_path.empty? child = create_or_find(relative_path.split('/').first) children.delete(child) end |
#root? ⇒ Boolean
39 40 41 |
# File 'lib/ghq/cache/directory.rb', line 39 def root? self.name.include?('/') end |