Class: Guard::Brakeman
- Inherits:
-
Plugin
- Object
- Plugin
- Guard::Brakeman
- Defined in:
- lib/guard/brakeman.rb
Overview
The Brakeman guard that gets notifications about the following Guard events: ‘start`, `stop`, `reload`, `run_all` and `run_on_changes`.
Instance Method Summary collapse
-
#initialize(options = { }) ⇒ Brakeman
constructor
A new instance of Brakeman.
-
#run_all ⇒ Object
Gets called when all checks should be run.
-
#run_on_changes(paths) ⇒ Object
Gets called when watched paths and files have changes.
-
#start ⇒ Object
Gets called once when Guard starts.
Constructor Details
#initialize(options = { }) ⇒ Brakeman
Returns a new instance of Brakeman.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/guard/brakeman.rb', line 13 def initialize( = { }) super ::Brakeman.instance_variable_set(:@quiet, [:quiet]) if [:skip_checks] [:skip_checks] = [:skip_checks].map do |val| # mimic Brakeman::set_options behavior val[0,5] == "Check" ? val : "Check" << val end end if [:url_safe_methods] [:url_safe_methods]= [:url_safe_methods].map do |val| val.to_sym end end # chatty implies notifications [:notifications] = true if [:chatty] # TODO mixing the use of this attr, good to match? Bad to couple? @options = { :notifications => true, :run_on_start => false, :chatty => false, :min_confidence => 2, :quiet => false, :support_rescanning => true, # Will be needed for Brakeman 7.0 }.merge!() @scanner_opts = ::Brakeman::({:app_path => '.'}.merge(@options)) end |
Instance Method Details
#run_all ⇒ Object
Gets called when all checks should be run.
66 67 68 69 70 71 72 |
# File 'lib/guard/brakeman.rb', line 66 def run_all fail "no scanner opts (start not called?)!" if @scanner_opts.nil? tracker.run_checks ::Brakeman.filter_warnings tracker, @scanner_opts print_failed throw :task_has_failed if tracker.filtered_warnings.any? end |
#run_on_changes(paths) ⇒ Object
Gets called when watched paths and files have changes.
79 80 81 82 83 84 85 |
# File 'lib/guard/brakeman.rb', line 79 def run_on_changes paths return run_all unless tracker.checks info "\n\nrescanning #{paths}, running all checks" unless [:quiet] report = ::Brakeman::rescan(tracker, paths) print_changed(report) throw :task_has_failed if report.any_warnings? end |
#start ⇒ Object
Gets called once when Guard starts.
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/guard/brakeman.rb', line 51 def start @scanner_opts = ::Brakeman::({:app_path => '.'}.merge(@options)) @options.merge!(@scanner_opts) if @options[:run_on_start] run_all elsif @options[:chatty] Guard::Compat::Notifier.notify("Brakeman is ready to work!", :title => "Brakeman started", :image => :pending) end end |