Class: CodeManifest::Manifest

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(patterns) ⇒ Manifest

Returns a new instance of Manifest.



12
13
14
15
16
# File 'lib/code_manifest/manifest.rb', line 12

def initialize(patterns)
  @rules ||= Array(patterns).map do |pattern|
    Rule.new(pattern)
  end
end

Instance Attribute Details

#rulesObject (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

#digestObject



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

#filesObject



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

Returns:

  • (Boolean)


46
47
48
# File 'lib/code_manifest/manifest.rb', line 46

def matches_all?(paths)
  matches(paths) == paths
end