Class: GitHooks::GitAdapter

Inherits:
Object
  • Object
show all
Includes:
Grit
Defined in:
lib/git_hooks/git_adapter.rb

Defined Under Namespace

Classes: Commits

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGitAdapter

Returns a new instance of GitAdapter.



47
48
49
# File 'lib/git_hooks/git_adapter.rb', line 47

def initialize
  @repo = Repo.new(GitAdapter.find_git_root)
end

Instance Attribute Details

#repoObject (readonly)

Returns the value of attribute repo.



45
46
47
# File 'lib/git_hooks/git_adapter.rb', line 45

def repo
  @repo
end

Class Method Details

.find_git_rootObject



57
58
59
60
61
62
63
64
65
# File 'lib/git_hooks/git_adapter.rb', line 57

def self.find_git_root
  current_dir = Dir.pwd.split('/')
  while current_dir.last !~ /\.git/
    current_dir.pop
    break if current_dir.empty?
  end

  return current_dir.join('/')
end

Instance Method Details

#find_commits_since_last_receive(prev_rev, current_rev, ref_name = 'master') ⇒ Object



51
52
53
54
55
# File 'lib/git_hooks/git_adapter.rb', line 51

def find_commits_since_last_receive(prev_rev, current_rev, ref_name = 'master')
  commits = repo.commits_between(prev_rev, current_rev)

  return Commits.new(commits, ref_name, @repo)
end