Class: Ghq::Cache::Directory

Inherits:
Struct
  • Object
show all
Defined in:
lib/ghq/cache/directory.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDirectory

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

#childrenObject

Returns the value of attribute children

Returns:

  • (Object)

    the current value of children



3
4
5
# File 'lib/ghq/cache/directory.rb', line 3

def children
  @children
end

#countObject

Returns the value of attribute count

Returns:

  • (Object)

    the current value of count



3
4
5
# File 'lib/ghq/cache/directory.rb', line 3

def count
  @count
end

#nameObject

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



3
4
5
# File 'lib/ghq/cache/directory.rb', line 3

def name
  @name
end

#parentObject

Returns the value of attribute parent

Returns:

  • (Object)

    the current value of 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_rootObject



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

Returns:

  • (Boolean)


39
40
41
# File 'lib/ghq/cache/directory.rb', line 39

def root?
  self.name.include?('/')
end