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.



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

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.



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

def path
  @path
end

Instance Method Details

#add_smell(smell) ⇒ Object



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

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

#code_locObject



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

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



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

def flay(report)
  @flay_report = report
end

#locObject



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

def loc
  stats_report.loc
end

#smellsObject



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

def smells
  @smells.all
end

#smelly?Boolean

Returns:

  • (Boolean)


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

def smelly?
  smells.any?
end