Class: Crystalball::GitRepo

Inherits:
Object
  • Object
show all
Defined in:
lib/crystalball/git_repo.rb

Overview

Wrapper class representing Git repository

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repo_path) ⇒ GitRepo

Returns a new instance of GitRepo.

Parameters:

  • repo_path (Pathname)

    path to repository root folder



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_pathObject (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)

Returns:

  • (Boolean)


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.

Returns:



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

Parameters:

  • from (String) (defaults to: 'HEAD')

    starting commit to build a diff. Default: HEAD

  • to (String) (defaults to: nil)

    ending commit to build a diff. Default: nil, will build diff of uncommitted changes

Returns:



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

Returns:

  • (Boolean)


34
35
36
# File 'lib/crystalball/git_repo.rb', line 34

def respond_to_missing?(method, *)
  repo.respond_to?(method, false)
end