Class: AppEngine::Admin::UpdateCheck
- Inherits:
-
Object
- Object
- AppEngine::Admin::UpdateCheck
- Defined in:
- lib/appengine-tools/update_check.rb
Constant Summary collapse
- NAG_FILE =
"~/.appcfg_rb_nag"
- MAX_NAG_FREQUENCY =
60 * 60 * 24 * 7
- DEFAULT_URL =
'http://appengine-jruby.googlecode.com/hg/updatecheck'
Instance Method Summary collapse
- #can_nag? ⇒ Boolean
- #check_for_updates ⇒ Object
- #find_gem_version(name) ⇒ Object
-
#initialize(approot, url = nil, nag_file = nil) ⇒ UpdateCheck
constructor
A new instance of UpdateCheck.
- #local_versions ⇒ Object
- #nag ⇒ Object
- #parse_nag_file ⇒ Object
- #remote_versions ⇒ Object
- #write_nag_file(options) ⇒ Object
Constructor Details
#initialize(approot, url = nil, nag_file = nil) ⇒ UpdateCheck
Returns a new instance of UpdateCheck.
33 34 35 36 37 |
# File 'lib/appengine-tools/update_check.rb', line 33 def initialize(approot, url=nil, nag_file=nil) @url = url || DEFAULT_URL @approot = approot @nag_file = nag_file || File.(NAG_FILE) end |
Instance Method Details
#can_nag? ⇒ Boolean
112 113 114 |
# File 'lib/appengine-tools/update_check.rb', line 112 def can_nag? parse_nag_file['opt_in'] end |
#check_for_updates ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/appengine-tools/update_check.rb', line 65 def check_for_updates local = local_versions unless local['google-appengine'] puts '=> Skipping update check' return end latest = remote_versions local.each do |name, version| current = latest[name] if version && version < current prefix = if name == 'google-appengine' update_msg = "=> Please run sudo gem update google-appengine." else update_msg = "=> Please update your Gemfile." end puts "=> There is a new version of #{name}: #{current} " + "(You have #{version})" puts update_msg end end end |
#find_gem_version(name) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/appengine-tools/update_check.rb', line 48 def find_gem_version(name) IO.foreach("#{@approot}/.gems/bundler_gems/environment.rb") do |line| if line =~ %r(/gems/#{name}-(\w+\.\w+.\w+)[/"]) return Gem::Version.new($1) end end rescue nil nil end |
#local_versions ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/appengine-tools/update_check.rb', line 39 def local_versions sdk_version = Gem::Version.new(AppEngine::VERSION) rescue nil { 'google-appengine' => sdk_version, 'appengine-apis' => find_gem_version('appengine-apis'), 'dm-appengine' => find_gem_version('dm-appengine'), } end |
#nag ⇒ Object
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/appengine-tools/update_check.rb', line 101 def nag nag = parse_nag_file return if Time.now.to_i - nag['timestamp'] < MAX_NAG_FREQUENCY check_for_updates nag['timestamp'] = Time.now.to_i write_nag_file(nag) rescue OpenURI::HTTPError, Errno::ENOENT # check_for_updates will raise an error if we're not online # just ignore it, and don't update the nag timestamp. end |
#parse_nag_file ⇒ Object
87 88 89 90 91 92 93 |
# File 'lib/appengine-tools/update_check.rb', line 87 def parse_nag_file @nag ||= if File.exist?(@nag_file) YAML.load_file(@nag_file) else {'opt_in' => true, 'timestamp' => 0} end end |
#remote_versions ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/appengine-tools/update_check.rb', line 57 def remote_versions versions = YAML.load(open(@url).read) versions.inject({}) do |versions, (name, version)| versions[name] = Gem::Version.new(version) versions end end |
#write_nag_file(options) ⇒ Object
95 96 97 98 99 |
# File 'lib/appengine-tools/update_check.rb', line 95 def write_nag_file() open(@nag_file, 'w') do |file| file.write(YAML.dump()) end end |