Class: CodeManifest::Manifest
- Inherits:
-
Object
- Object
- CodeManifest::Manifest
- Defined in:
- lib/code_manifest/manifest.rb
Constant Summary collapse
- GLOB_OPTIONS =
File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB
Instance Attribute Summary collapse
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
- #digest ⇒ Object
- #files ⇒ Object
-
#initialize(patterns) ⇒ Manifest
constructor
A new instance of Manifest.
- #matches(paths) ⇒ Object
- #matches_all?(paths) ⇒ Boolean
Constructor Details
Instance Attribute Details
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
10 11 12 |
# File 'lib/code_manifest/manifest.rb', line 10 def rules @rules end |
Instance Method Details
#digest ⇒ Object
26 27 28 29 30 31 |
# File 'lib/code_manifest/manifest.rb', line 26 def digest @digest ||= begin digests = files.map { |file| Digest::MD5.file(CodeManifest.root.join(file)).hexdigest } Digest::MD5.hexdigest(digests.join).freeze end end |
#files ⇒ Object
19 20 21 22 23 24 |
# File 'lib/code_manifest/manifest.rb', line 19 def files @files ||= begin matched_files = matches(Dir.glob(inclusion_rules.map(&:glob), GLOB_OPTIONS, base: CodeManifest.root)).uniq files_with_relative_path(matched_files).freeze end end |
#matches(paths) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/code_manifest/manifest.rb', line 33 def matches(paths) Array(paths).select do |path| cached_match = if @cache.key?(path) @cache.fetch(path) else @cache[path] = [ inclusion_rules.any? { |rule| rule.match?(path) }, exclusion_rules.any? { |rule| rule.match?(path) } ] end cached_match.first && !cached_match.last end.sort! end |
#matches_all?(paths) ⇒ Boolean
48 49 50 |
# File 'lib/code_manifest/manifest.rb', line 48 def matches_all?(paths) matches(paths).size == paths.size end |