Module: Bibliothecary::Analyser::Matchers

Defined in:
lib/bibliothecary/analyser/matchers.rb

Instance Method Summary collapse

Instance Method Details

#mapping_entry_match?(matcher, details, info) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
36
37
38
39
40
# 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) ⇒ Boolean

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.

Returns:

  • (Boolean)


47
48
49
# 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) ⇒ Object



19
20
21
22
23
24
25
# 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) ⇒ Object



4
5
6
7
8
9
10
# 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) ⇒ Object



12
13
14
15
16
17
# 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) ⇒ Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/bibliothecary/analyser/matchers.rb', line 51

def match_info?(info)
  first_matching_mapping_details(info).any?
end