Class: Git::Path

Inherits:
Object
  • Object
show all
Defined in:
lib/git/path.rb

Overview

A base class that represents and validates a filesystem path

Use for tracking things relevant to a Git repository, such as the working directory or index file.

Direct Known Subclasses

Index, Repository, WorkingDirectory

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, must_exist: true) ⇒ Path

Returns a new instance of Path.

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
# File 'lib/git/path.rb', line 12

def initialize(path, must_exist: true)
  path = File.expand_path(path)

  raise ArgumentError, 'path does not exist', [path] if must_exist && !File.exist?(path)

  @path = path
end

Instance Attribute Details

#path

Returns the value of attribute path.



10
11
12
# File 'lib/git/path.rb', line 10

def path
  @path
end

Instance Method Details

#readable?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/git/path.rb', line 20

def readable?
  File.readable?(@path)
end

#to_s



28
29
30
# File 'lib/git/path.rb', line 28

def to_s
  @path
end

#writable?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/git/path.rb', line 24

def writable?
  File.writable?(@path)
end