Class: RemindMe::Runner

Inherits:
Object
  • Object
show all
Extended by:
Parallel::ProcessorCount, BailOut, Utils::Logger, Utils::Versions
Defined in:
lib/remind_me/runner.rb

Constant Summary

Constants included from Utils::Versions

Utils::Versions::INSTALLED_GEMS

Class Method Summary collapse

Methods included from BailOut

bail_out!

Methods included from Utils::Logger

colorize, green, log_error, log_info, log_with_rails, rails_being_used?, red

Methods included from Utils::Versions

compare_version_numbers, condition_comparators, gem_installed?, gem_version, invalid_condition_message, valid_condition?, valid_version_string?

Class Method Details

.all_file_comments(file, parser) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/remind_me/runner.rb', line 53

def self.all_file_comments(file, parser)
  parser.reset
  source = File.read(file).force_encoding(parser.default_encoding)
  buffer = Parser::Source::Buffer.new(file)
  buffer.source = source
  parser.parse_with_comments(buffer).last
end

.check_reminders(check_path: '.') ⇒ Object



31
32
33
# File 'lib/remind_me/runner.rb', line 31

def self.check_reminders(check_path: '.')
  Utils::ResultPrinter.new(collect_reminders(check_path)).print_results
end

.collect_reminders(path) ⇒ Object



35
36
37
38
39
40
41
42
43
44
# File 'lib/remind_me/runner.rb', line 35

def self.collect_reminders(path)
  files = relevant_ruby_files(path)
  return if files.empty?

  Parallel.flat_map(in_groups(files, processor_count, false)) do |files|
    parser = silent_parser
    raw_comments = collect_relevant_comments(files, parser)
    raw_comments.flat_map { |raw_comment| RemindMe::Reminder::Generator.generate(raw_comment[0], raw_comment[1], parser) }
  end
end

.processor_countObject

:nocov:



103
104
105
106
107
108
109
# File 'lib/remind_me/runner.rb', line 103

def self.processor_count
  if using_old_parallel_gem?
    super
  else
    Parallel.processor_count
  end
end

.relevant_ruby_files(parse_path) ⇒ Object



68
69
70
71
72
73
74
# File 'lib/remind_me/runner.rb', line 68

def self.relevant_ruby_files(parse_path)
  Parallel.flat_map(in_groups(collect_ruby_files(parse_path), processor_count, false)) do |files|
    files.select do |file|
      IO.foreach(file).any? { |line| line.include?('REMIND_ME:') }
    end
  end
end

.silent_parserObject



46
47
48
49
50
51
# File 'lib/remind_me/runner.rb', line 46

def self.silent_parser
  parser = Parser::CurrentRuby.new
  parser.diagnostics.consumer = ->(_message) {}
  parser.diagnostics.ignore_warnings = true
  parser
end

.using_old_parallel_gem?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/remind_me/runner.rb', line 19

def self.using_old_parallel_gem?
  gem_version('parallel') < Gem::Version.new('1.23.0')
end