Class: Tuxedo::ReekParser

Inherits:
Object
  • Object
show all
Defined in:
lib/tuxedo/reek_parser.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReekParser

Returns a new instance of ReekParser.



5
6
7
# File 'lib/tuxedo/reek_parser.rb', line 5

def initialize
  self.result = { }
end

Instance Attribute Details

#resultObject

Returns the value of attribute result.



3
4
5
# File 'lib/tuxedo/reek_parser.rb', line 3

def result
  @result
end

Instance Method Details

#clean_reek(reek_output) ⇒ Object



24
25
26
# File 'lib/tuxedo/reek_parser.rb', line 24

def clean_reek(reek_output)
  reek_output.gsub("- !ruby/object:Reek::SmellWarning","- smell_warning:")
end

#get_error(hash) ⇒ Object



42
43
44
# File 'lib/tuxedo/reek_parser.rb', line 42

def get_error(hash)
  hash["smell"]["subclass"]
end

#get_file(hash) ⇒ Object



46
47
48
# File 'lib/tuxedo/reek_parser.rb', line 46

def get_file(hash)
  hash["location"]["source"]
end

#get_lines(hash) ⇒ Object



50
51
52
# File 'lib/tuxedo/reek_parser.rb', line 50

def get_lines(hash)
  hash["location"]["lines"]
end

#parse_reek(reek_output) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/tuxedo/reek_parser.rb', line 9

def parse_reek(reek_output)
  reek_hash = YAML::load(clean_reek(reek_output))
  unless reek_hash
    puts "No reek errors found."
    return self
  end

  reek_hash.each do |hash|
    error = process_hash(hash)
    push_error(error)
  end

  return self
end

#process_hash(hash) ⇒ Object



36
37
38
39
40
# File 'lib/tuxedo/reek_parser.rb', line 36

def process_hash(hash)
  Tuxedo::Error.new( :name => get_error(hash),
                         :source => get_file(hash),
                         :line => get_lines(hash))
end

#push_error(error) ⇒ Object



28
29
30
31
32
33
34
# File 'lib/tuxedo/reek_parser.rb', line 28

def push_error(error)
  if self.result[ error.name.to_sym ]
    self.result[ error.name.to_sym ] << error
  else
    self.result[ error.name.to_sym ] = [ error ]
  end
end