Class: RubyAudit::CLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/ruby_audit/cli.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby_audit/cli.rb', line 12

def check
  update unless options[:no_update]

  scanner = Scanner.new
  vulnerable = false

  scanner.scan(ignore: options[:ignore]) do |result|
    vulnerable = true
    print_advisory result.gem, result.advisory
  end

  if vulnerable
    say 'Vulnerabilities found!', :red
    exit 1
  else
    say 'No vulnerabilities found', :green
  end
end

#updateObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ruby_audit/cli.rb', line 32

def update
  say 'Updating ruby-advisory-db ...'

  case Database.update!
  when true
    say 'Updated ruby-advisory-db', :green
  when false
    say 'Failed updating ruby-advisory-db!', :red
    exit 1
  when nil
    say 'Skipping update', :yellow
  end

  database = Database.new
  puts "ruby-advisory-db: #{database.size} advisories, " \
       "last updated #{database.last_updated_at.utc}"
end

#versionObject



51
52
53
54
55
# File 'lib/ruby_audit/cli.rb', line 51

def version
  database = Database.new
  puts "#{File.basename($PROGRAM_NAME)} #{VERSION} " \
       "(advisories: #{database.size}, last updated: #{database.last_updated_at.utc})"
end