Class: HP::Cloud::Checker
- Inherits:
-
Object
- Object
- HP::Cloud::Checker
- Defined in:
- lib/hpcloud/checker.rb
Constant Summary collapse
- @@home =
nil
Instance Attribute Summary collapse
-
#deferment ⇒ Object
Returns the value of attribute deferment.
-
#file ⇒ Object
Returns the value of attribute file.
-
#latest ⇒ Object
Returns the value of attribute latest.
-
#url ⇒ Object
Returns the value of attribute url.
Class Method Summary collapse
Instance Method Summary collapse
- #comparo(latest) ⇒ Object
-
#initialize ⇒ Checker
constructor
A new instance of Checker.
- #process ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Checker
Returns a new instance of Checker.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hpcloud/checker.rb', line 31 def initialize if @@home.nil? @@home = ENV['HOME'] end @directory = @@home + "/.hpcloud/" @file = @directory + ".checker" config = Config.new @url = config.get(:checker_url) @deferment = config.get(:checker_deferment) end |
Instance Attribute Details
#deferment ⇒ Object
Returns the value of attribute deferment.
27 28 29 |
# File 'lib/hpcloud/checker.rb', line 27 def deferment @deferment end |
#file ⇒ Object
Returns the value of attribute file.
27 28 29 |
# File 'lib/hpcloud/checker.rb', line 27 def file @file end |
#latest ⇒ Object
Returns the value of attribute latest.
27 28 29 |
# File 'lib/hpcloud/checker.rb', line 27 def latest @latest end |
#url ⇒ Object
Returns the value of attribute url.
27 28 29 |
# File 'lib/hpcloud/checker.rb', line 27 def url @url end |
Class Method Details
.home_directory=(dir) ⇒ Object
42 43 44 |
# File 'lib/hpcloud/checker.rb', line 42 def self.home_directory=(dir) @@home = dir end |
.split(value) ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/hpcloud/checker.rb', line 46 def self.split(value) value = value.strip.split('.') major = value[0] if value.length > 0 minor = value[1] if value.length > 1 build = value[2] if value.length > 2 return major, minor, build end |
Instance Method Details
#comparo(latest) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/hpcloud/checker.rb', line 54 def comparo(latest) lmajor, lminor, lbuild = Checker.split(latest) major, minor, build = Checker.split(HP::Cloud::VERSION) lmajor = lmajor.to_i lminor = lminor.to_i lbuild = lbuild.to_i major = major.to_i minor = minor.to_i build = build.to_i return true if lmajor > major return false if lmajor < major return true if lminor > minor return false if lminor < minor return true if lbuild > build return false end |
#process ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/hpcloud/checker.rb', line 71 def process return false if @deferment == 0 return false if @url.nil? if File.exists?(@file) begin mtime = File.new(@file).mtime now = Time.now rescue return false end return false if ((now - mtime) < @deferment) end begin FileUtils.mkdir_p(@directory) FileUtils.touch(@file) rescue end begin @latest = open(@url).read.strip return false unless comparo(@latest) rescue return false end return true end |
#reset ⇒ Object
99 100 101 |
# File 'lib/hpcloud/checker.rb', line 99 def reset FileUtils.rm_rf(@file) end |