Module: RuboCop::Cop::EngineApi

Extended by:
NodePattern::Macros
Included in:
Flexport::EngineApiBoundary
Defined in:
lib/rubocop/cop/mixin/engine_api.rb

Overview

Functionality for reading Rails Engine API declaration files.

Constant Summary collapse

API_FILE_DETAILS =
{
  allowlist: {
    file_basename: '_allowlist.rb',
    array_matcher: :allowlist_array
  },
  whitelist: {
    file_basename: '_whitelist.rb',
    array_matcher: :allowlist_array
  },
  legacy_dependents: {
    file_basename: '_legacy_dependents.rb',
    array_matcher: :legacy_dependents_array
  }
}.freeze

Instance Method Summary collapse

Instance Method Details

#engine_api_files_modified_time_checksum(engines_path) ⇒ Object



44
45
46
47
48
# File 'lib/rubocop/cop/mixin/engine_api.rb', line 44

def engine_api_files_modified_time_checksum(engines_path)
  api_files = Dir.glob(File.join(engines_path, '**/app/api/**/api/**/*'))
  mtimes = api_files.sort.map { |f| File.mtime(f) }
  Digest::SHA1.hexdigest(mtimes.join)
end

#extract_api_list(engines_path, engine, api_file) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rubocop/cop/mixin/engine_api.rb', line 27

def extract_api_list(engines_path, engine, api_file)
  key = cache_key(engine, api_file)
  @cache ||= {}
  cached = @cache[key]
  return cached if cached

  details = API_FILE_DETAILS[api_file]

  path = full_path(engines_path, engine, details)
  return [] unless File.file?(path)

  list = extract_array(path, details[:array_matcher])

  @cache[key] = list
  list
end