Class: VagrantPlugins::Openstack::VersionChecker
- Inherits:
-
Object
- Object
- VagrantPlugins::Openstack::VersionChecker
- Includes:
- Singleton
- Defined in:
- lib/vagrant-openstack-provider/version_checker.rb
Instance Attribute Summary collapse
-
#check_enabled ⇒ Object
boolean attribute to disbale version checker.
-
#status ⇒ Object
:latest, :outdated or :unstable.
Instance Method Summary collapse
-
#check ⇒ Object
Check the latest version from rubygem and set the status.
-
#initialize ⇒ VersionChecker
constructor
A new instance of VersionChecker.
Constructor Details
#initialize ⇒ VersionChecker
Returns a new instance of VersionChecker.
24 25 26 27 28 29 30 |
# File 'lib/vagrant-openstack-provider/version_checker.rb', line 24 def initialize @status = nil @check_enabled = true check = ENV['VAGRANT_OPENSTACK_VERSION_CKECK'] @check_enabled = false if check && check.upcase == 'DISABLED' end |
Instance Attribute Details
#check_enabled ⇒ Object
boolean attribute to disbale version checker
22 23 24 |
# File 'lib/vagrant-openstack-provider/version_checker.rb', line 22 def check_enabled @check_enabled end |
#status ⇒ Object
:latest, :outdated or :unstable
A version is considered unstable if it does not respect the pattern or if it is greater than the latest from rubygem
17 18 19 |
# File 'lib/vagrant-openstack-provider/version_checker.rb', line 17 def status @status end |
Instance Method Details
#check ⇒ Object
Check the latest version from rubygem and set the status
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/vagrant-openstack-provider/version_checker.rb', line 35 def check return :latest unless @check_enabled return @status unless @status.nil? begin latest = Gem.latest_spec_for('vagrant-openstack-provider').version.version rescue # If for any reason the version of the latest pulished # version can't be found we don't fail in any way return :latest end current = VagrantPlugins::Openstack::VERSION unless current =~ VERSION_PATTERN @status = :unstable I18n.t('vagrant_openstack.version_unstable') return end if latest.eql? current @status = :latest return end v_latest = latest.split('.').map(&:to_i) v_current = current.split('.').map(&:to_i) i_latest = v_latest[2] + v_latest[1] * 1000 + v_latest[0] * 1_000_000 i_current = v_current[2] + v_current[1] * 1000 + v_current[0] * 1_000_000 if i_current > i_latest @status = :unstable I18n.t('vagrant_openstack.version_unstable') return end @status = :outdated I18n.t('vagrant_openstack.version_outdated', latest: latest, current: current) end |