Class: YardJunk::Janitor

Inherits:
Object
  • Object
show all
Defined in:
lib/yard-junk/janitor.rb,
lib/yard-junk/janitor/resolver.rb,
lib/yard-junk/janitor/yard_options.rb,
lib/yard-junk/janitor/base_reporter.rb,
lib/yard-junk/janitor/html_reporter.rb,
lib/yard-junk/janitor/text_reporter.rb

Defined Under Namespace

Classes: BaseReporter, HtmlReporter, Resolver, TextReporter, YardOptions

Instance Method Summary collapse

Constructor Details

#initialize(mode: :full, pathes: nil) ⇒ Janitor

Returns a new instance of Janitor.



9
10
11
12
# File 'lib/yard-junk/janitor.rb', line 9

def initialize(mode: :full, pathes: nil)
  @mode = mode
  @files = expand_pathes(pathes)
end

Instance Method Details

#exit_codeObject



49
50
51
52
53
54
55
# File 'lib/yard-junk/janitor.rb', line 49

def exit_code
  case
  when !errors.empty? then 2
  when !problems.empty? then 1
  else 0
  end
end

#report(*args, **opts) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/yard-junk/janitor.rb', line 37

def report(*args, **opts)
  guess_reporters(*args, **opts).each do |reporter|
    reporter.section('Errors', 'severe code or formatting problems', errors)
    reporter.section('Problems', 'mistyped tags or other typos in documentation', problems)

    reporter.stats(**stats)
    reporter.finalize
  end

  exit_code
end

#run(*opts) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/yard-junk/janitor.rb', line 14

def run(*opts)
  YARD::Registry.clear # Somehow loads all Ruby stdlib classes before Rake task started...
  Logger.instance.format = nil # Nothing shouuld be printed

  puts "Running YardJunk janitor (version #{YardJunk::VERSION})...\n\n"

  @duration = Benchmark.realtime do
    command = YARD::CLI::Yardoc.new
    command.run(*prepare_options(opts))
    Resolver.resolve_all(command.options) unless mode == :sanity
  end

  self
end

#statsObject



29
30
31
32
33
34
35
# File 'lib/yard-junk/janitor.rb', line 29

def stats
  {
    errors: errors.count,
    problems: problems.count,
    duration: @duration || 0
  }
end