Class: Bundler::Audit::CLI

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

Constant Summary collapse

DEFAULT_PRESENTER =
'plain'
Error =
Class.new(RuntimeError)
PresenterUnkown =
Class.new(Error)
PresenterInvalid =
Class.new(Error)

Instance Method Summary collapse

Instance Method Details

#checkObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bundler/audit/cli.rb', line 45

def check
  update if options[:update]

  scanner    = Scanner.new
  presenter = presenter_klass(options[:format]).new(self.shell, options)

  scanner.scan(:ignore => options.ignore) do |result|
    case result
    when Scanner::InsecureSource
      presenter.push_warning "Insecure Source URI found: #{result.source}"
    when Scanner::UnpatchedGem
      presenter.push_advisory result
    end
  end

  presenter.print_report
  exit presenter.exit_code

rescue Error => e
  say e.message, :red
  exit 1
end

#presenter_klass(presenter_string) ⇒ Object (protected)



103
104
105
106
107
108
109
110
# File 'lib/bundler/audit/cli.rb', line 103

def presenter_klass(presenter_string)
  presenter_name = presenter_string.capitalize.to_sym
  raise PresenterUnkown, "Unknown Presenter '#{presenter_name}'" unless Presenter.const_defined? presenter_name

  Presenter.const_get presenter_name
rescue NameError
  raise PresenterInvalid, "Invalid Presenter Name '#{presenter_name}'"
end

#say(message = "", color = nil) ⇒ Object (protected)



98
99
100
101
# File 'lib/bundler/audit/cli.rb', line 98

def say(message="", color=nil)
  color = nil unless $stdout.tty?
  super(message.to_s, color)
end

#updateObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/bundler/audit/cli.rb', line 71

def update
  say("Updating ruby-advisory-db ...") unless options.quiet?

  case Database.update!(quiet: options.quiet?)
  when true
    say("Updated ruby-advisory-db", :green) unless options.quiet?
  when false
    say "Failed updating ruby-advisory-db!", :red
    exit 1
  when nil
    say "Skipping update", :yellow
  end

  unless options.quiet?
    puts("ruby-advisory-db: #{Database.new.size} advisories")
  end
end

#versionObject



90
91
92
93
94
# File 'lib/bundler/audit/cli.rb', line 90

def version
  database = Database.new

  puts "#{File.basename($0)} #{VERSION} (advisories: #{database.size})"
end