Class: Plus2Version::VersionFinder

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

Class Method Summary collapse

Class Method Details

.as_hashObject



4
5
6
7
8
# File 'lib/plus2_version/version_finder.rb', line 4

def as_hash
  {
    :log    => git('log HEAD^.. --shortstat --no-color --decorate').split("\n")
  }
end

.git(cmd) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/plus2_version/version_finder.rb', line 14

def git(cmd)
  git = Plus2Version.git_path || 'git'
  Dir.chdir(Rails.root) do
    `#{git} #{cmd}`.chomp.tap {|output|
      output.replace('problem running git') unless $?.success?
    }
  end
end

.log_at(name) ⇒ Object



39
40
41
# File 'lib/plus2_version/version_finder.rb', line 39

def log_at(name)
  snapshots[name.to_s][:log]
end

.shaObject



10
11
12
# File 'lib/plus2_version/version_finder.rb', line 10

def sha
  git('rev-parse HEAD').chomp
end

.sha_at(name) ⇒ Object



35
36
37
# File 'lib/plus2_version/version_finder.rb', line 35

def sha_at(name)
  snapshots[name.to_s][:sha]
end

.snapshot_version(name) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/plus2_version/version_finder.rb', line 27

def snapshot_version(name)
  name = name.to_s
  snapshots[name] = {
    :sha => sha,
    :log => as_hash
  }
end

.snapshotsObject



23
24
25
# File 'lib/plus2_version/version_finder.rb', line 23

def snapshots
  @snapshots ||= Hash.new {|h,k| h[k] = {} }
end