Class: Glyptodont::Checker

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/glyptodont/checker.rb

Overview

Main class where all the work happens

Constant Summary collapse

DEFAULT_THRESHOLD =
10
DEFAULT_MAX_AGE_IN_DAYS =
14
DEFAULT_KEYWORDS =
%w[
  FIXME
  HACK
  TODO
  XXX
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Checker

Returns a new instance of Checker.



24
25
26
27
# File 'lib/glyptodont/checker.rb', line 24

def initialize(args)
  @options = Options.new(args)
  @configuration = Configuration.new(directory)
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



42
43
44
# File 'lib/glyptodont/checker.rb', line 42

def configuration
  @configuration
end

#optionsObject (readonly)

Returns the value of attribute options.



42
43
44
# File 'lib/glyptodont/checker.rb', line 42

def options
  @options
end

Instance Method Details

#checkObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/glyptodont/checker.rb', line 29

def check
  todos = TodoResearcher.new(directory, ignore, keywords).research

  checks = [
    Checkers::Counter.new(todos: todos, threshold: threshold),
    Checkers::Age.new(todos: todos, threshold: max_age_in_days)
  ].freeze

  checks.each { |check| puts check.check }

  checks.all?(&:passed?)
end

#keywordsObject



57
58
59
# File 'lib/glyptodont/checker.rb', line 57

def keywords
  options.keywords || configuration.keywords || DEFAULT_KEYWORDS
end

#max_age_in_daysObject



53
54
55
# File 'lib/glyptodont/checker.rb', line 53

def max_age_in_days
  options.max_age_in_days || configuration.max_age_in_days || DEFAULT_MAX_AGE_IN_DAYS
end

#thresholdObject



49
50
51
# File 'lib/glyptodont/checker.rb', line 49

def threshold
  options.threshold || configuration.threshold || DEFAULT_THRESHOLD
end