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.



184
185
186
187
# File 'lib/myprecious.rb', line 184

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

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



188
189
190
# File 'lib/myprecious.rb', line 188

def dir
  @dir
end

Instance Method Details

#git_infoObject



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

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

#origin_remoteObject



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

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

#repo_nameObject



198
199
200
# File 'lib/myprecious.rb', line 198

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