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
28 29 30 31 32 33 |
# File 'lib/code_manifest/manifest.rb', line 28 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
18 19 20 21 22 23 24 25 26 |
# File 'lib/code_manifest/manifest.rb', line 18 def files @files ||= begin inclusion_files = Dir.glob(inclusion_rules.map(&:glob), GLOB_OPTIONS, base: CodeManifest.root) inclusion_files.delete_if do |file| exclusion_rules.any? { |rule| rule.match?(file) } end files_with_relative_path(inclusion_files).sort!.freeze end end |
#matches(paths) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/code_manifest/manifest.rb', line 35 def matches(paths) result_paths = Array(paths).select do |path| inclusion_rules.any? { |rule| rule.match?(path) } end result_paths.reject! do |path| exclusion_rules.any? { |rule| rule.match?(path) } end result_paths.sort! end |
#matches_all?(paths) ⇒ Boolean
46 47 48 |
# File 'lib/code_manifest/manifest.rb', line 46 def matches_all?(paths) matches(paths) == paths end |