Class: DontRepeatYourself::ProjectReporterBase

Inherits:
Object
  • Object
show all
Defined in:
lib/dont_repeat_yourself/reporter.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ ProjectReporterBase

Returns a new instance of ProjectReporterBase.



25
26
27
28
29
30
31
32
# File 'lib/dont_repeat_yourself/reporter.rb', line 25

def initialize(name)
  @name = name
  @simian_runner = DontRepeatYourself::SimianRunner.new      
  
  # Default values
  @maximum_number_of_duplicate_lines_i_want_in_my_project = 0
  @report_type = DontRepeatYourself::DEFAULT_REPORT
end

Instance Attribute Details

#maximum_number_of_duplicate_lines_i_want_in_my_projectObject (readonly)

Returns the value of attribute maximum_number_of_duplicate_lines_i_want_in_my_project.



23
24
25
# File 'lib/dont_repeat_yourself/reporter.rb', line 23

def maximum_number_of_duplicate_lines_i_want_in_my_project
  @maximum_number_of_duplicate_lines_i_want_in_my_project
end

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/dont_repeat_yourself/reporter.rb', line 23

def name
  @name
end

#report_typeObject (readonly)

Returns the value of attribute report_type.



23
24
25
# File 'lib/dont_repeat_yourself/reporter.rb', line 23

def report_type
  @report_type
end

Class Method Details

.build_reporter(reporter, basedir) ⇒ Object



84
85
86
87
88
89
90
# File 'lib/dont_repeat_yourself/reporter.rb', line 84

def self.build_reporter(reporter, basedir)
  case reporter
    when 'ruby' then DontRepeatYourself::RubyProjectReporter.new(basedir)
    when 'rails' then DontRepeatYourself::RailsProjectReporter.new(basedir)
    when 'plugin' then DontRepeatYourself::RailsPluginProjectReporter.new(basedir)
  end
end

Instance Method Details

#basedirObject



62
63
64
# File 'lib/dont_repeat_yourself/reporter.rb', line 62

def basedir
  @simian_runner.basedir
end

#descriptionObject



75
76
77
# File 'lib/dont_repeat_yourself/reporter.rb', line 75

def description
  "DRY\n" << "  - with a threshold of #{@simian_runner.threshold} duplicate lines"
end

#failure_messageObject



79
80
81
82
# File 'lib/dont_repeat_yourself/reporter.rb', line 79

def failure_message      
  "expected #{@name} to have less or equal #{@maximum_number_of_duplicate_lines_i_want_in_my_project} duplicate lines :\n
     DRY Report:\n#{report}\n"
end

#ignoring_the_directory(path) ⇒ Object



57
58
59
60
# File 'lib/dont_repeat_yourself/reporter.rb', line 57

def ignoring_the_directory(path)
  @simian_runner.ignore_directory(path)
  self
end

#ignoring_the_file(path) ⇒ Object



52
53
54
55
# File 'lib/dont_repeat_yourself/reporter.rb', line 52

def ignoring_the_file(path)
  @simian_runner.ignore_file(path)
  self
end

#is_dry?Boolean

TODO Not very readable: you have to read the code of run_simian to understand

Returns:

  • (Boolean)


71
72
73
# File 'lib/dont_repeat_yourself/reporter.rb', line 71

def is_dry?
  run_simian.duplicate_line_count <= @maximum_number_of_duplicate_lines_i_want_in_my_project        
end

#patterns_of_directories_to_search_for_duplicate_linesObject



34
35
36
# File 'lib/dont_repeat_yourself/reporter.rb', line 34

def patterns_of_directories_to_search_for_duplicate_lines
  @simian_runner.patterns_of_directories_to_search_for_duplicate_lines
end

#reportObject



66
67
68
# File 'lib/dont_repeat_yourself/reporter.rb', line 66

def report
  DontRepeatYourself::FormatterFactory.create_report(@report_type, run_simian)
end

#with_threshold_of_duplicate_lines(threshold) ⇒ Object

Fluent interface methods



39
40
41
42
# File 'lib/dont_repeat_yourself/reporter.rb', line 39

def with_threshold_of_duplicate_lines(threshold)
  @simian_runner.threshold = threshold        
  return self
end