Class: MyPrecious::GitInfoExtractor

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

Overview

Tool for getting information about the Git repository associated with a directory

Constant Summary collapse

URL_PATTERN =
/\/([^\/]+)\.git$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ GitInfoExtractor

Returns a new instance of GitInfoExtractor.



190
191
192
193
# File 'lib/myprecious.rb', line 190

def initialize(dir)
  super()
  @dir = dir
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



194
195
196
# File 'lib/myprecious.rb', line 194

def dir
  @dir
end

Instance Method Details

#git_infoObject



196
197
198
# File 'lib/myprecious.rb', line 196

def git_info
  @git_info ||= Git.open(self.dir)
end

#origin_remoteObject



200
201
202
# File 'lib/myprecious.rb', line 200

def origin_remote
  git_info.remotes.find {|r| r.name == 'origin'}
end

#repo_nameObject



204
205
206
# File 'lib/myprecious.rb', line 204

def repo_name
  @repo_name ||= (URL_PATTERN =~ origin_remote.url) && $1
end