Class: CodeHunter::Brakeman::Summarizer
- Inherits:
-
Object
- Object
- CodeHunter::Brakeman::Summarizer
- Defined in:
- lib/code_hunter/brakeman/summarizer.rb
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #content ⇒ Object
- #find_line(element) ⇒ Object
- #find_message(element) ⇒ Object
- #find_path(element) ⇒ Object
- #find_url(element) ⇒ Object
-
#initialize(options = {}) ⇒ Summarizer
constructor
A new instance of Summarizer.
- #rows ⇒ Object
- #summarize ⇒ Object
- #summarize_with_file_existence_check ⇒ Object
- #tree ⇒ Object
- #warning_elements ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Summarizer
Returns a new instance of Summarizer.
8 9 10 |
# File 'lib/code_hunter/brakeman/summarizer.rb', line 8 def initialize( = {}) @options = end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
6 7 8 |
# File 'lib/code_hunter/brakeman/summarizer.rb', line 6 def @options end |
Instance Method Details
#content ⇒ Object
54 55 56 |
# File 'lib/code_hunter/brakeman/summarizer.rb', line 54 def content Brakeman::TEMPORAL_PATHNAME.read end |
#find_line(element) ⇒ Object
26 27 28 |
# File 'lib/code_hunter/brakeman/summarizer.rb', line 26 def find_line(element) (element)[/near line (\d+)/, 1].try(:to_i) end |
#find_message(element) ⇒ Object
30 31 32 |
# File 'lib/code_hunter/brakeman/summarizer.rb', line 30 def (element) element.css(".warning_message").first.child.text.strip end |
#find_path(element) ⇒ Object
34 35 36 |
# File 'lib/code_hunter/brakeman/summarizer.rb', line 34 def find_path(element) element.css(".warning_message").first.css("caption").text.strip end |
#find_url(element) ⇒ Object
38 39 40 |
# File 'lib/code_hunter/brakeman/summarizer.rb', line 38 def find_url(element) element.css("a").first.try(:attr, "href") end |
#rows ⇒ Object
46 47 48 |
# File 'lib/code_hunter/brakeman/summarizer.rb', line 46 def rows tree.css("tr") end |
#summarize ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/code_hunter/brakeman/summarizer.rb', line 12 def summarize rows.map do |element| if element.css(".warning_message").any? { :service => "brakeman", :line => find_line(element), :path => find_path(element), :message => (element), :url => find_url(element), } end end.compact end |
#summarize_with_file_existence_check ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/code_hunter/brakeman/summarizer.rb', line 58 def summarize_with_file_existence_check if Brakeman::TEMPORAL_PATHNAME.exist? summarize_without_file_existence_check else warn "Brakeman output file is not found" end end |
#tree ⇒ Object
50 51 52 |
# File 'lib/code_hunter/brakeman/summarizer.rb', line 50 def tree Nokogiri.HTML(content) end |
#warning_elements ⇒ Object
42 43 44 |
# File 'lib/code_hunter/brakeman/summarizer.rb', line 42 def warning_elements tree.css(".warning_message") end |