Class: Watchr::FileAnalyse

Inherits:
Object
  • Object
show all
Includes:
Analysers::Flog, Analysers::Reek
Defined in:
lib/watchr/file_analyse.rb

Overview

Analyse for one given file. All the different metric analyse data are collected in order to output reasonable recommendations for a code improvements.

Constant Summary

Constants included from SmellTypes

SmellTypes::ALL_SMELLS

Constants included from Analysers::Flog

Analysers::Flog::COMPLEX_METHOD_THRESHOLD, Analysers::Flog::COMPLEX_OBJECT_THRESHOLD, Analysers::Flog::VERY_COMPLEX_METHOD_THRESHOLD, Analysers::Flog::VERY_COMPLEX_OBJECT_THRESHOLD

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Analysers::Reek

#analyse_reek

Methods included from Analysers::Flog

#analyse_flog

Constructor Details

#initialize(path) ⇒ FileAnalyse

Craete new file analyse.

Parameters:

  • Path (String)

    to file.



24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/watchr/file_analyse.rb', line 24

def initialize(path)
  @path = path
  @smells = SmellsCollector.new
  
  begin
    analyse_flog(FlogMetric::Report.new([path]))
  rescue Racc::ParseError => e 
    puts e
  end
  
  analyse_reek(ReekMetric::Report.new([path]))
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



17
18
19
# File 'lib/watchr/file_analyse.rb', line 17

def path
  @path
end

Instance Method Details

#add_smell(smell) ⇒ Object



64
65
66
# File 'lib/watchr/file_analyse.rb', line 64

def add_smell(smell)
  @smells.add(smell)
end

#code_locObject



45
46
47
# File 'lib/watchr/file_analyse.rb', line 45

def code_loc
  stats_report.code_loc
end

#flay(report) ⇒ Object

Store the flay report, which was evaluated on global basis to check for duplications across multiple files.

Parameters:

Returns:

  • nil



56
57
58
# File 'lib/watchr/file_analyse.rb', line 56

def flay(report)
  @flay_report = report
end

#locObject



41
42
43
# File 'lib/watchr/file_analyse.rb', line 41

def loc
  stats_report.loc
end

#smellsObject



60
61
62
# File 'lib/watchr/file_analyse.rb', line 60

def smells
  @smells.all
end

#smelly?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/watchr/file_analyse.rb', line 37

def smelly?
  smells.any?
end