Class: Git::Path
- Inherits:
-
Object
- Object
- Git::Path
- 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
Instance Attribute Summary collapse
-
#path
Returns the value of attribute path.
Instance Method Summary collapse
-
#initialize(path, check_path = nil, must_exist: nil) ⇒ Path
constructor
A new instance of Path.
- #readable? ⇒ Boolean
- #to_s
- #writable? ⇒ Boolean
Constructor Details
#initialize(path, check_path = nil, must_exist: nil) ⇒ Path
Returns a new instance of Path.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/git/path.rb', line 12 def initialize(path, check_path = nil, must_exist: nil) unless check_path.nil? Git::Deprecation.warn( 'The "check_path" argument is deprecated and ' \ 'will be removed in a future version. Use "must_exist:" instead.' ) end # default is true must_exist = must_exist.nil? && check_path.nil? ? true : must_exist || check_path path = File.(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
30 31 32 |
# File 'lib/git/path.rb', line 30 def readable? File.readable?(@path) end |
#to_s
38 39 40 |
# File 'lib/git/path.rb', line 38 def to_s @path end |
#writable? ⇒ Boolean
34 35 36 |
# File 'lib/git/path.rb', line 34 def writable? File.writable?(@path) end |