Class: Bundler::Plumber::CLI

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

Instance Method Summary collapse

Instance Method Details

#checkObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/bundler/plumber/cli.rb', line 39

def check
  update if options[:update]

  scanner    = Scanner.new
  leaky = false

  scanner.scan(ignore: options.ignore) do |result|
    leaky = true

    case result
    when Scanner::UnpatchedGem
      print_advisory result.gem, result.advisory
    end
  end

  if leaky
    say "Leaks found!", :red
    exit 1
  else
    say("No leaks found", :green) unless options.quiet?
  end
end


101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/bundler/plumber/cli.rb', line 101

def print_advisory(gem, advisory)
  say "Name: ", :red
  say gem.name

  say "Version: ", :red
  say gem.version

  say "URL: ", :red
  say advisory.url

  if options.verbose?
    say "Description:", :red
    say

    print_wrapped advisory.description, :indent => 2
    say
  else

    say "Title: ", :red
    say advisory.title
  end

  unless advisory.patched_versions.empty?
    say "Solution: upgrade to ", :red
    say advisory.patched_versions.join(', ')
  else
    say "Solution: ", :red
    say "remove or disable this gem until a patch is available!", [:red, :bold]
  end

  say
end


97
98
99
# File 'lib/bundler/plumber/cli.rb', line 97

def print_warning(message)
  say message, :yellow
end

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



92
93
94
95
# File 'lib/bundler/plumber/cli.rb', line 92

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

#updateObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/bundler/plumber/cli.rb', line 65

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

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

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

#versionObject



84
85
86
87
88
# File 'lib/bundler/plumber/cli.rb', line 84

def version
  database = Database.new

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