Module: Aperitiiif::Linters

Included in:
Batch
Defined in:
lib/aperitiiif/batch/linters.rb

Overview

TO DO COMMENT

Instance Method Summary collapse

Instance Method Details

#lintObject



17
18
19
20
# File 'lib/aperitiiif/batch/linters.rb', line 17

def lint
  puts 'Linting...'.colorize(:cyan)
  puts 'Passed ✓'.colorize(:green) unless report_failures.any?
end

#lintersObject



7
8
9
10
11
12
13
14
15
# File 'lib/aperitiiif/batch/linters.rb', line 7

def linters
  @linters ||= [
    method(:warn_nil_record_items),
    method(:warn_duplicate_record_ids),
    method(:warn_duplicate_image_names),
    method(:warn_missing_labels),
    method(:warn_stray_files)
  ]
end

#report_failuresObject



22
23
24
# File 'lib/aperitiiif/batch/linters.rb', line 22

def report_failures
  linters.map(&:call)
end

#warn_duplicate_image_namesObject

has smell :reek:DuplicateMethodCall has smell :reek:TooManyStatements rubocop: disable Metrics/AbcSize



50
51
52
53
54
55
56
57
58
59
# File 'lib/aperitiiif/batch/linters.rb', line 50

def warn_duplicate_image_names
  files = Dir.glob("#{config.source_dir}/**/*").select { |file| File.file? file }
  files.map! { |file| Utils.rm_ext file.sub(config.source_dir, '') }
  duplicate_names = files.select { |file| files.count(file) > 1 }.uniq
  return false if duplicate_names.empty?

  warn "Found #{duplicate_names.length} duplicate image name(s):".colorze(:orange)
  duplicate_names.each { |name| puts Utils.prune_prefix_junk(name).colorize(:yellow) }
  true
end

#warn_duplicate_record_idsObject

has smell :reek:TooManyStatements



37
38
39
40
41
42
43
44
45
# File 'lib/aperitiiif/batch/linters.rb', line 37

def warn_duplicate_record_ids
  ids     = records.map(&:id)
  dup_ids = ids.select { |id| ids.count(id) > 1 }.uniq
  return false if dup_ids.empty?

  warn "Found #{dup_ids.length} non-unique record id value(s):".colorze(:orange)
  dup_ids.each { |id| puts id.colorize(:yellow) }
  true
end

#warn_missing_labelsObject

has smell :reek:TooManyStatements



63
64
65
66
67
68
69
70
# File 'lib/aperitiiif/batch/linters.rb', line 63

def warn_missing_labels
  no_label_records = records.select { |record| record.label.to_s.empty? }
  return false if no_label_records.empty?

  warn "Found #{no_label_records.length} record(s) missing labels (strongly encouraged):".colorze(:orange)
  no_label_records.each { |record| puts record.id.colorize(:yellow) }
  true
end

#warn_nil_record_itemsObject

has smell :reek:TooManyStatements



27
28
29
30
31
32
33
34
# File 'lib/aperitiiif/batch/linters.rb', line 27

def warn_nil_record_items
  nil_record_items = items.select { |item| item.record.blank? }
  return false if nil_record_items.empty?

  warn "Could not find record(s) for #{nil_record_items.length} items:".colorze(:orange)
  nil_record_items.each { |item| puts Utils.rm_batch_namespace(item.id).colorize(:yellow) }
  true
end

#warn_stray_filesObject

has smell :reek:TooManyStatements rubocop:disable Metrics/AbcSize



74
75
76
77
78
79
80
81
82
83
# File 'lib/aperitiiif/batch/linters.rb', line 74

def warn_stray_files
  stray_files = Dir.glob("#{config.source_dir}/**/*")
  stray_files.select! { |file| File.file?(file) && !file.end_with?(*ALLOWED_SRC_FORMATS) }
  return false if stray_files.empty?

  warn "Found #{stray_files.length} stray file(s) with unaccepted file types:".colorze(:orange)
  stray_files.each { |file| puts file.colorize(:yellow) }
  puts "(Accepted file extensions: #{ALLOWED_SRC_FORMATS.join(', ')})".colorize(:pink)
  true
end