module Bibliothecary::Analyser::Matchers

Public Instance Methods

mapping_entry_match?(matcher, details, info) click to toggle source
# File lib/bibliothecary/analyser/matchers.rb, line 27
def mapping_entry_match?(matcher, details, info)
  if matcher.call(info.relative_path)
    # we only want to load contents if we don't have them already
    # and there's a content_matcher method to use
    return true if details[:content_matcher].nil?
    # this is the libraries.io case where we won't load all .xml
    # files (for example) just to look at their contents, we'll
    # assume they are not manifests.
    return false if info.contents.nil?
    return send(details[:content_matcher], info.contents)
  else
    return false
  end
end
match?(filename, contents = nil) click to toggle source

this is broken with contents=nil because it can’t look at file contents, so skips manifests that are ambiguously a manifest considering only the filename. However, those are the semantics that libraries.io uses since it doesn’t have the files locally.

# File lib/bibliothecary/analyser/matchers.rb, line 47
def match?(filename, contents = nil)
  match_info?(FileInfo.new(nil, filename, contents))
end
match_extension(filename, case_insensitive: false) click to toggle source
# File lib/bibliothecary/analyser/matchers.rb, line 19
def match_extension(filename, case_insensitive: false)
  if case_insensitive
    lambda { |path| path.downcase.end_with?(filename.downcase) }
  else
    lambda { |path| path.end_with?(filename) }
  end
end
match_filename(filename, case_insensitive: false) click to toggle source
# File lib/bibliothecary/analyser/matchers.rb, line 4
def match_filename(filename, case_insensitive: false)
  if case_insensitive
    lambda { |path| path.downcase == filename.downcase || path.downcase.end_with?("/" + filename.downcase) }
  else
    lambda { |path| path == filename || path.end_with?("/" + filename) }
  end
end
match_filenames(*filenames) click to toggle source
# File lib/bibliothecary/analyser/matchers.rb, line 12
def match_filenames(*filenames)
  lambda do |path|
    filenames.any? { |f| path == f } ||
      filenames.any? { |f| path.end_with?("/" + f) }
  end
end
match_info?(info) click to toggle source
# File lib/bibliothecary/analyser/matchers.rb, line 51
def match_info?(info)
  first_matching_mapping_details(info).any?
end

Private Instance Methods

first_matching_mapping_details(info) click to toggle source
# File lib/bibliothecary/analyser/matchers.rb, line 57
def first_matching_mapping_details(info)
  mapping
    .find { |matcher, details| mapping_entry_match?(matcher, details, info) }
    &.last || {}
end