Module: Bibliothecary::Analyser::Matchers
- Defined in:
- lib/bibliothecary/analyser/matchers.rb
Instance Method Summary collapse
- #mapping_entry_match?(matcher, details, info) ⇒ Boolean
-
#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.
- #match_extension(filename, case_insensitive: false) ⇒ Object
- #match_filename(filename, case_insensitive: false) ⇒ Object
- #match_filenames(*filenames) ⇒ Object
- #match_info?(info) ⇒ Boolean
Instance Method Details
#mapping_entry_match?(matcher, details, info) ⇒ Boolean
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/bibliothecary/analyser/matchers.rb', line 29 def mapping_entry_match?(matcher, details, info) return false unless 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? send(details[:content_matcher], info.contents) 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.
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
21 22 23 24 25 26 27 |
# File 'lib/bibliothecary/analyser/matchers.rb', line 21 def match_extension(filename, case_insensitive: false) if case_insensitive ->(path) { path.downcase.end_with?(filename.downcase) } else ->(path) { path.end_with?(filename) } end end |
#match_filename(filename, case_insensitive: false) ⇒ Object
6 7 8 9 10 11 12 |
# File 'lib/bibliothecary/analyser/matchers.rb', line 6 def match_filename(filename, case_insensitive: false) if case_insensitive ->(path) { path.downcase == filename.downcase || path.downcase.end_with?("/#{filename.downcase}") } else ->(path) { path == filename || path.end_with?("/#{filename}") } end end |
#match_filenames(*filenames) ⇒ Object
14 15 16 17 18 19 |
# File 'lib/bibliothecary/analyser/matchers.rb', line 14 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
51 52 53 |
# File 'lib/bibliothecary/analyser/matchers.rb', line 51 def match_info?(info) first_matching_mapping_details(info).any? end |