Module: Atig::UpdateChecker

Defined in:
lib/atig/update_checker.rb

Class Method Summary collapse

Class Method Details

.commitsObject



5
6
7
8
9
10
# File 'lib/atig/update_checker.rb', line 5

def commits
  uri = URI("http://github.com/api/v1/json/mzp/atig/commits/master")
  http = Atig::Http.new
  res = http.http(uri).request http.req(:get, uri)
  JSON.parse(res.body)['commits']
end

.git?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/atig/update_checker.rb', line 23

def git?
  system('which git > /dev/null 2>&1')
end

.latestObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/atig/update_checker.rb', line 27

def latest
  unless git? then
    []
  else
    cs      = commits
    latest  = cs.first['id'][/^[0-9a-z]{40}$/]
    raise "github API changed?" unless latest

    if local_repos?(latest) then
      []
    else
      current  = cs.map {|i| i['id'] }.index(server_version)
      if current then
        cs[0...current]
      else
        cs
      end.map {|i| i['message'] }
    end
  end
rescue Errno::ECONNREFUSED, Timeout::Error => e
  []
end

.local_repos?(rev) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/atig/update_checker.rb', line 19

def local_repos?(rev)
  system("git show #{rev} > /dev/null 2>&1")
end

.server_versionObject



12
13
14
15
16
17
# File 'lib/atig/update_checker.rb', line 12

def server_version
  @server_version ||= instance_eval {
    head = `git rev-parse HEAD 2>/dev/null`.chomp
    head.empty?? "unknown" : head
  }
end