guard-brakeman 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/guard/brakeman.rb +19 -22
  2. metadata +7 -7
@@ -6,7 +6,7 @@ require 'brakeman/scanner'
6
6
  module Guard
7
7
 
8
8
  # The Brakeman guard that gets notifications about the following
9
- # Guard events: `start`, `stop`, `reload`, `run_all` and `run_on_change`.
9
+ # Guard events: `start`, `stop`, `reload`, `run_all` and `run_on_changes`.
10
10
  #
11
11
  class Brakeman < Guard
12
12
  def initialize(watchers = [], options = { })
@@ -39,9 +39,7 @@ module Guard
39
39
  @scanner_opts = ::Brakeman::set_options({:app_path => '.'}.merge(@options))
40
40
  @options.merge!(@scanner_opts)
41
41
 
42
- @scanner = ::Brakeman::Scanner.new(@scanner_opts)
43
-
44
- @tracker = @scanner.process
42
+ @tracker = ::Brakeman::Scanner.new(@scanner_opts).process
45
43
 
46
44
  if @options[:run_on_start]
47
45
  run_all
@@ -66,7 +64,7 @@ module Guard
66
64
  # @param [Array<String>] paths the changed paths and files
67
65
  # @raise [:task_has_failed] when stop has failed
68
66
  #
69
- def run_on_change(paths)
67
+ def run_on_changes paths
70
68
  return run_all unless @tracker.checks
71
69
 
72
70
  UI.info "\n\nrescanning #{paths}, running all checks"
@@ -82,7 +80,7 @@ module Guard
82
80
 
83
81
  icon = report.all_warnings.count > 0 ? :failed : :success
84
82
 
85
- all_warnings = reject_below_threshold(report.all_warnings)
83
+ all_warnings = report.all_warnings
86
84
 
87
85
  puts all_warnings.sort_by { |w| w.confidence }
88
86
 
@@ -104,46 +102,44 @@ module Guard
104
102
  message = ""
105
103
  should_alert = false
106
104
 
107
- fixed_warnings = reject_below_threshold(report.fixed_warnings)
105
+ fixed_warnings = report.fixed_warnings
108
106
  if fixed_warnings.any?
109
107
  icon = :success
110
- results_notification = "#{fixed_warnings.length} fixed warning(s)\n"
108
+ results_notification = pluralize(fixed_warnings.length, "fixed warning")
111
109
  UI.info(UI.send(:color, results_notification, 'green')) # janky
112
110
 
113
111
  should_alert = true
114
112
  message += results_notification
115
113
 
116
114
  puts fixed_warnings.sort_by { |w| w.confidence }
117
- puts
115
+ puts ""
118
116
  end
119
117
 
120
- new_warnings = reject_below_threshold(report.new_warnings)
118
+ new_warnings = report.new_warnings
121
119
  if new_warnings.any?
122
- new_warning_message = "#{new_warnings.length} new warning(s)\n"
123
- UI.error new_warning_message
124
- message += new_warning_message
120
+ new_warning_message = pluralize(new_warnings.length, "new warning")
121
+ UI.info(UI.send(:color, new_warning_message, 'red')) # janky
125
122
 
123
+ message += new_warning_message
126
124
  should_alert = true
127
125
  icon = :failed
128
126
 
129
127
  puts new_warnings.sort_by { |w| w.confidence }
130
- puts
128
+ puts ""
131
129
  end
132
130
 
133
- existing_warnings = reject_below_threshold(report.existing_warnings)
131
+ existing_warnings = report.existing_warnings
134
132
  if existing_warnings.any?
135
133
  should_alert = true if @options[:chatty]
136
134
  icon ||= :pending
137
135
 
138
- existing_warning_message = "#{existing_warnings.length} previous warning(s)\n"
136
+ existing_warning_message = pluralize(existing_warnings.length, "previous warning")
139
137
  UI.warning existing_warning_message
140
138
  message += existing_warning_message
141
139
 
142
140
  puts existing_warnings.sort_by { |w| w.confidence }
143
141
  end
144
142
 
145
-
146
-
147
143
  if @options[:output_files]
148
144
  write_report
149
145
  message += "\nResults written to #{@options[:output_files]}"
@@ -154,10 +150,6 @@ module Guard
154
150
  end
155
151
  end
156
152
 
157
- def reject_below_threshold(warnings)
158
- warnings.reject {|w| w.confidence > (3 - @options[:min_confidence].to_i)}
159
- end
160
-
161
153
  def write_report
162
154
  @options[:output_files].each_with_index do |output_file, i|
163
155
  File.open output_file, "w" do |f|
@@ -165,5 +157,10 @@ module Guard
165
157
  end
166
158
  end
167
159
  end
160
+
161
+ # stolen from rails
162
+ def pluralize(count, singular, plural = nil)
163
+ "#{count || 0} " + ((count == 1 || count =~ /^1(\.0+)?$/) ? singular : (plural || singular.pluralize))
164
+ end
168
165
  end
169
166
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guard-brakeman
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 11
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 4
8
+ - 5
9
9
  - 0
10
- version: 0.4.0
10
+ version: 0.5.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Neil Matatall
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-05-03 00:00:00 Z
19
+ date: 2012-07-22 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: guard
@@ -26,12 +26,12 @@ dependencies:
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- hash: 21
29
+ hash: 19
30
30
  segments:
31
31
  - 1
32
- - 0
33
32
  - 1
34
- version: 1.0.1
33
+ - 0
34
+ version: 1.1.0
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency