Class: Needy::Git

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir, branch) ⇒ Git

Returns a new instance of Git.



79
80
81
82
83
# File 'lib/needy.rb', line 79

def initialize dir, branch
  self.dir = File.join File.expand_path(dir), '.git'
  self.branch = branch
  self.log_opt = ''
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



77
78
79
# File 'lib/needy.rb', line 77

def branch
  @branch
end

#dirObject

Returns the value of attribute dir.



77
78
79
# File 'lib/needy.rb', line 77

def dir
  @dir
end

#log_optObject

Returns the value of attribute log_opt.



77
78
79
# File 'lib/needy.rb', line 77

def log_opt
  @log_opt
end

Instance Method Details

#author(name) ⇒ Object



99
100
101
# File 'lib/needy.rb', line 99

def author name
  self.log_opt += " --author=#{name}"
end

#exec(*args) ⇒ Object



89
90
91
# File 'lib/needy.rb', line 89

def exec *args
  system("#{git_cmd} #{args.map(&:to_s).join(' ')}")
end

#git_cmdObject



85
86
87
# File 'lib/needy.rb', line 85

def git_cmd
  "git --git-dir=#{dir}"
end

#whenObject



93
94
95
96
97
# File 'lib/needy.rb', line 93

def when
  open "|#{git_cmd} log #{branch} #{log_opt} --pretty=%ct -n1" do |f|
    Time.at(f.gets.chomp.to_i)
  end
end