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.



70
71
72
73
74
# File 'lib/needy.rb', line 70

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.



68
69
70
# File 'lib/needy.rb', line 68

def branch
  @branch
end

#dirObject

Returns the value of attribute dir.



68
69
70
# File 'lib/needy.rb', line 68

def dir
  @dir
end

#log_optObject

Returns the value of attribute log_opt.



68
69
70
# File 'lib/needy.rb', line 68

def log_opt
  @log_opt
end

Instance Method Details

#author(name) ⇒ Object



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

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

#exec(*args) ⇒ Object



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

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

#git_cmdObject



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

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

#whenObject



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

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