Top Level Namespace

Defined Under Namespace

Modules: VersionCheck

Instance Method Summary collapse

Instance Method Details

#version_check(*versions) ⇒ Object

simple version check

used version MUST always be greater or equal than minimum requirement


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/version/check.rb', line 12

def version_check( *versions )
 
    outdated = []   ## list of outdated entries

    versions.each do |rec|
        name         = rec[0]
        ##  convert "2.0.17" to  [2,0,17] or
        ##          "2.1"    to  [2,1]     
        ## note: use Integer and NOT to_i; will through exception if version is not a number
        min_version  = rec[1].split( '.' ).map { |part| Integer(part) }
        used_version = rec[2].split( '.' ).map { |part| Integer(part) }

        ## check for minimum version requirement 
        min_version.zip( used_version ) do |part|
            min_num  = part[0]
            used_num = part[1] || 0    ## support unlikley edge case (used_version has less version parts than min_version)
            if used_num > min_num 
                ## used version is greater; stop comparing 
                break   
            elsif used_num == min_num
                ## continue compare with next version number part
                next  
            else
                ## used version is smaller; add and report outdated (!!) entry; stop comparing  
                outdated << rec
                break
            end
        end
    end

    outdated
end

#version_check!(*versions) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/version/check.rb', line 46

def version_check!( *versions )
  outdated = version_check( *versions )
      
  if outdated.size > 0   ## any outdated gems/libraries
      puts "!!! error: version check failed - #{outdated.size} outdated gem(s):"
      outdated.each do |rec|
          name         = rec[0]
          min_version  = rec[1]
          used_version = rec[2]
          puts "   #{name} - min version required #{min_version} > used/installed version #{used_version}"
      end
      puts
      puts "sorry - cannot continue; please update the outdated gem(s)"
      
      exit 1
  end   
end