Class: Todidnt::GitRepo

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

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ GitRepo

Returns a new instance of GitRepo.



3
4
5
6
7
8
9
10
11
12
# File 'lib/todidnt/git_repo.rb', line 3

def initialize(path)
  expanded_path = File.expand_path(path)

  if File.exist?(File.join(expanded_path, '.git'))
    @working_dir = expanded_path
  else
    $stderr.puts "Whoops, #{expanded_path} is not a git repository!"
    exit
  end
end

Instance Method Details

#run(&blk) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/todidnt/git_repo.rb', line 14

def run(&blk)
  unless Dir.pwd == @working_dir
    Dir.chdir(@working_dir) do
      yield @working_dir
    end
  else
    yield
  end
end