Class: Crystalball::GitRepo
- Inherits:
-
Object
- Object
- Crystalball::GitRepo
- Defined in:
- lib/crystalball/git_repo.rb
Overview
Wrapper class representing Git repository
Instance Attribute Summary collapse
-
#repo_path ⇒ Object
readonly
Returns the value of attribute repo_path.
Class Method Summary collapse
-
.exists?(path) ⇒ Boolean
Check if given path is under git control (contains .git folder).
-
.open(repo_path) ⇒ Crystalball::GitRepo
Instance for given path.
Instance Method Summary collapse
-
#diff(from = 'HEAD', to = nil) ⇒ SourceDiff
Creates diff.
-
#initialize(repo_path) ⇒ GitRepo
constructor
A new instance of GitRepo.
-
#method_missing(method, *args, &block) ⇒ Object
Proxy all unknown calls to ‘Git` object.
- #respond_to_missing?(method) ⇒ Boolean
Constructor Details
#initialize(repo_path) ⇒ GitRepo
Returns a new instance of GitRepo.
25 26 27 |
# File 'lib/crystalball/git_repo.rb', line 25 def initialize(repo_path) @repo_path = repo_path end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Proxy all unknown calls to ‘Git` object
30 31 32 |
# File 'lib/crystalball/git_repo.rb', line 30 def method_missing(method, *args, &block) repo.public_send(method, *args, &block) end |
Instance Attribute Details
#repo_path ⇒ Object (readonly)
Returns the value of attribute repo_path.
9 10 11 |
# File 'lib/crystalball/git_repo.rb', line 9 def repo_path @repo_path end |
Class Method Details
.exists?(path) ⇒ Boolean
Check if given path is under git control (contains .git folder)
19 20 21 |
# File 'lib/crystalball/git_repo.rb', line 19 def exists?(path) path.join('.git').directory? end |
.open(repo_path) ⇒ Crystalball::GitRepo
Returns instance for given path.
13 14 15 16 |
# File 'lib/crystalball/git_repo.rb', line 13 def open(repo_path) path = Pathname(repo_path) new(path) if exists?(path) end |
Instance Method Details
#diff(from = 'HEAD', to = nil) ⇒ SourceDiff
Creates diff
43 44 45 |
# File 'lib/crystalball/git_repo.rb', line 43 def diff(from = 'HEAD', to = nil) SourceDiff.new(repo.diff(from, to)) end |
#respond_to_missing?(method) ⇒ Boolean
34 35 36 |
# File 'lib/crystalball/git_repo.rb', line 34 def respond_to_missing?(method, *) repo.respond_to?(method, false) end |