Module: Atig::UpdateChecker
- Defined in:
- lib/atig/update_checker.rb
Class Method Summary collapse
- .commits ⇒ Object
- .git? ⇒ Boolean
- .git_repos? ⇒ Boolean
- .latest ⇒ Object
- .local_repos?(rev) ⇒ Boolean
- .server_version ⇒ Object
Class Method Details
.commits ⇒ Object
5 6 7 8 9 10 |
# File 'lib/atig/update_checker.rb', line 5 def commits uri = URI("https://api.github.com/repos/mzp/atig/commits") http = Atig::Http.new res = http.http(uri).request http.req(:get, uri) JSON.parse(res.body) end |
.git? ⇒ Boolean
27 28 29 |
# File 'lib/atig/update_checker.rb', line 27 def git? system('which git > /dev/null 2>&1') end |
.git_repos? ⇒ Boolean
23 24 25 |
# File 'lib/atig/update_checker.rb', line 23 def git_repos? File.exists? File.('../../../.git', __FILE__) end |
.latest ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/atig/update_checker.rb', line 31 def latest unless git? then [] else cs = commits latest = cs.first['sha'][/^[0-9a-z]{40}$/] raise "github API changed?" unless latest if local_repos?(latest) then [] else current = cs.map {|i| i['sha'] }.index(server_version) if current then cs[0...current] else cs end.map {|i| i['commit']['message'] } end end rescue Errno::ECONNREFUSED, Timeout::Error => e [] end |
.local_repos?(rev) ⇒ 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_version ⇒ Object
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 |