Class: Envcheck

Inherits:
Object
  • Object
show all
Defined in:
lib/envcheck.rb

Constant Summary collapse

COMMANDS =

Constants ============================================================

{
  :ruby => {
    :version => /^ruby (\S+)/
  },
  :rubygems => {
    :bin => 'gem',
    :version => /(\S+)/
  },
  :bundler => {
    :bin => 'bundle',
    :version => /^Bundler version (.*)/
  },
  :passenger => {
    :version => /^Phusion Passenger version (\S+)/
  },
  :ImageMagick => {
    :bin => 'convert',
    :version => /^Version: ImageMagick (\S+)/
  },
  :mysql => {
    :version => /Ver\s+\S+\s+Distrib\s+(\S+),/
  }
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = nil) ⇒ Envcheck

Instance Methods =====================================================



36
37
38
# File 'lib/envcheck.rb', line 36

def initialize(options = nil)
  @options = options
end

Class Method Details

.reportObject

Class Methods ========================================================



30
31
32
# File 'lib/envcheck.rb', line 30

def self.report
  self.new.report
end

Instance Method Details

#find_in_path(file) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/envcheck.rb', line 46

def find_in_path(file)
  return unless (file)

  file = file.to_s
  
  self.path.each do |path|
    test_path = File.expand_path(file, path)
    if (File.exist?(test_path))
      return test_path
    end
  end
  
  nil
end

#pathObject



40
41
42
43
44
# File 'lib/envcheck.rb', line 40

def path
  @path ||= ENV['PATH'].split(/\:/).select do |path|
    path and path.match(/\S/)
  end
end

#reportObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/envcheck.rb', line 61

def report
  summary = ''
  
  COMMANDS.each do |command, config|
    summary << "#{command}\n"
    
    if (bin_found = self.find_in_path(config[:bin] || command))
      summary << "  #{bin_found}\n"
      
      version_string = `#{bin_found} #{config[:version_flag] || '--version'}`
      
      if (match = (config[:version] and version_string.match(config[:version])))
        summary << "  Version #{match[1]}\n"
      else
        summary << version_string.split(/\n/).collect { |s| "  #{s}\n" }.join('')
      end
    else
      summary << "  NOT FOUND\n"
    end
  end
  
  summary
end