Class: RubyGit::GitBinary
- Inherits:
-
Object
- Object
- RubyGit::GitBinary
- Defined in:
- lib/ruby_git/git_binary.rb
Overview
Sets and tracks the path to a git executable and reports the version
Class Method Summary collapse
-
.default_path(basename: 'git') ⇒ Pathname
Get the default path to to a git binary by searching the PATH.
Instance Method Summary collapse
-
#initialize(path = nil) ⇒ GitBinary
constructor
Return a new GitBinary object.
-
#path ⇒ Pathname
Retrieve the path to the git binary.
-
#path=(path) ⇒ Pathname
Sets the path to the git binary.
-
#to_s ⇒ String
Return the path as a string.
-
#version ⇒ Array<Integer>
The version of git referred to by the path.
Constructor Details
#initialize(path = nil) ⇒ GitBinary
Return a new GitBinary object
14 15 16 |
# File 'lib/ruby_git/git_binary.rb', line 14 def initialize(path = nil) @path = Pathname.new(path) unless path.nil? end |
Class Method Details
.default_path(basename: 'git') ⇒ Pathname
Get the default path to to a git binary by searching the PATH
69 70 71 |
# File 'lib/ruby_git/git_binary.rb', line 69 def self.default_path(basename: 'git') RubyGit::FileHelpers.which(basename) || raise("Could not find '#{basename}' in the PATH.") end |
Instance Method Details
#path ⇒ Pathname
Retrieve the path to the git binary
52 53 54 |
# File 'lib/ruby_git/git_binary.rb', line 52 def path @path || (@path = self.class.default_path) end |
#path=(path) ⇒ Pathname
Sets the path to the git binary
The given path must point to an executable file or a RuntimeError is raised.
32 33 34 35 36 37 38 39 |
# File 'lib/ruby_git/git_binary.rb', line 32 def path=(path) new_path = Pathname.new(path) raise "'#{new_path}' does not exist." unless new_path.exist? raise "'#{new_path}' is not a file." unless new_path.file? raise "'#{new_path}' is not executable." unless new_path.executable? @path = new_path end |
#to_s ⇒ String
Return the path as a string
102 103 104 |
# File 'lib/ruby_git/git_binary.rb', line 102 def to_s path.to_s end |
#version ⇒ Array<Integer>
The version of git referred to by the path
84 85 86 87 88 |
# File 'lib/ruby_git/git_binary.rb', line 84 def version output = `#{path} --version` version = output[/\d+\.\d+(\.\d+)+/] version.split('.').collect(&:to_i) end |