Class: CodeHunter::Brakeman::Summarizer

Inherits:
Object
  • Object
show all
Defined in:
lib/code_hunter/brakeman/summarizer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = {})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/code_hunter/brakeman/summarizer.rb', line 6

def options
  @options
end

Instance Method Details

#contentObject



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)
  find_message(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 find_message(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

#rowsObject



46
47
48
# File 'lib/code_hunter/brakeman/summarizer.rb', line 46

def rows
  tree.css("tr")
end

#summarizeObject



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 => find_message(element),
        :url     => find_url(element),
      }
    end
  end.compact
end

#summarize_with_file_existence_checkObject



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

#treeObject



50
51
52
# File 'lib/code_hunter/brakeman/summarizer.rb', line 50

def tree
  Nokogiri.HTML(content)
end

#warning_elementsObject



42
43
44
# File 'lib/code_hunter/brakeman/summarizer.rb', line 42

def warning_elements
  tree.css(".warning_message")
end