code_manifest 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94f0a39e5da9d75029e1834402dd5bda25d18510d7eca6291c67876caf5aad17
4
- data.tar.gz: 4b6d063a77093c6fd674964c15525808b6cd22e5d8d9d9770adb7c41421b4c9e
3
+ metadata.gz: e7020080ba5738c05558a6686645957049173b4cac3de5d4580c6203937d76b8
4
+ data.tar.gz: ca8973cbd93178c7852848ff2e8cd0b76a230dec908ad5c5c9594b0b8b44b6ba
5
5
  SHA512:
6
- metadata.gz: d3d985ad3f694e285c28ce13e3ec2036a939c5767ec8b6c6f6898d78b30eae608d68a680602155b5f866c78797328357ed34c88c0bd1818c22ffd659f9028d27
7
- data.tar.gz: 19d20c8fd6756f2b92cb068add7b22e9005ff6c41f75b065bf096251000c75ec7b676a238b26345f934b29f73a0324c36a2d915214dc9116ee2788de61114fae
6
+ metadata.gz: 5fd645efff6afb335ec37b352d74580e3b98b91a9773abeb56f9cd2228e2b6a8276bd9b2104b9ad6dd47bbf62b4dae7c721aac18fefef709c4f21ad7ab287464
7
+ data.tar.gz: 49285fbbefbf3777e5fdced3a3d039b3d4cf5fe9ace950c2cfd191fb150852469f62e27a0e660b20414564c6a8ec039221368885c2fc4376ee1a7cfc589c7554
@@ -7,12 +7,11 @@ module CodeManifest
7
7
  class Manifest
8
8
  GLOB_OPTIONS = File::FNM_PATHNAME | File::FNM_DOTMATCH | File::FNM_EXTGLOB
9
9
 
10
- attr_reader :root, :rules
10
+ attr_reader :rules
11
11
 
12
- def initialize(root, patterns)
13
- @root = root
12
+ def initialize(patterns)
14
13
  @rules ||= patterns.map do |pattern|
15
- Rule.new(root, pattern)
14
+ Rule.new(CodeManifest.root, pattern)
16
15
  end
17
16
  end
18
17
 
@@ -22,16 +21,20 @@ module CodeManifest
22
21
 
23
22
  def digest
24
23
  @digest ||= begin
25
- digests = files.map { |file| Digest::MD5.file(root.join(file)).hexdigest }
24
+ digests = files.map { |file| Digest::MD5.file(CodeManifest.root.join(file)).hexdigest }
26
25
  Digest::MD5.hexdigest(digests.join).freeze
27
26
  end
28
27
  end
29
28
 
30
29
  def matches(paths)
31
- result_paths = paths.select { |path| inclusion_rules.any? { |rule| rule.match?(path) } }
32
- result_paths.reject! { |path| exclusion_files.any? { |rule| rule.match?(path) } }
30
+ result_paths = paths.select do |path|
31
+ inclusion_rules.any? { |rule| rule.match?(path) }
32
+ end
33
+ result_paths.reject! do |path|
34
+ exclusion_files.any? { |rule| rule.match?(path) }
35
+ end
33
36
 
34
- result_paths
37
+ result_paths.sort!
35
38
  end
36
39
 
37
40
  private
@@ -56,7 +59,8 @@ module CodeManifest
56
59
  files.map do |file|
57
60
  pathname = Pathname.new(file)
58
61
  next if pathname.directory?
59
- pathname.relative_path_from(root.expand_path).to_s
62
+
63
+ pathname.relative_path_from(CodeManifest.root).to_s
60
64
  end.compact
61
65
  end
62
66
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CodeManifest
4
- VERSION = '1.1.0'
4
+ VERSION = '1.2.0'
5
5
  end
data/lib/code_manifest.rb CHANGED
@@ -8,7 +8,7 @@ require_relative 'code_manifest/manifest'
8
8
  module CodeManifest
9
9
  class Error < StandardError; end
10
10
 
11
- DOTFILE = '.code_manifest.yml'
11
+ MANIFEST_FILE = '.code_manifest.yml'
12
12
  KEY_PATTERN = /[a-z_0-9]+/.freeze
13
13
 
14
14
  class << self
@@ -16,33 +16,33 @@ module CodeManifest
16
16
  manifests[name.to_s]
17
17
  end
18
18
 
19
+ def root(start_path: Dir.pwd, reset: false)
20
+ @root = nil if reset
21
+ @root ||= find_root(start_path)
22
+ end
23
+
19
24
  private
20
25
 
21
26
  def manifests
22
27
  @manifests ||= begin
23
- manifest_file = traverse_files(DOTFILE, Dir.pwd)
24
-
25
- unless manifest_file
26
- raise "#{DOTFILE} was not found in your project directory, please check README for instructions."
27
- end
28
-
29
- root = Pathname.new(manifest_file).dirname
28
+ manifest_file = root.join(MANIFEST_FILE)
30
29
 
31
30
  load_manifest(manifest_file).each_with_object({}) do |(name, patterns), collection|
32
31
  next unless name.match?(KEY_PATTERN)
33
32
 
34
- raise ArgumentError, "#{name} defined multiple times in #{DOTFILE}" if collection.key?(name)
33
+ raise ArgumentError, "#{name} defined multiple times in #{MANIFEST_FILE}" if collection.key?(name)
35
34
 
36
- collection[name] = Manifest.new(root, patterns)
35
+ collection[name] = Manifest.new(patterns.flatten)
37
36
  end
38
37
  end
39
38
  end
40
39
 
41
- def traverse_files(filename, start_dir)
42
- Pathname.new(start_dir).expand_path.ascend do |dir|
43
- file = dir.join(filename)
44
- return file.to_s if file.exist?
40
+ def find_root(path)
41
+ Pathname.new(path).expand_path.ascend do |dir|
42
+ return dir if dir.join(MANIFEST_FILE).exist?
45
43
  end
44
+
45
+ raise "#{MANIFEST_FILE} was not found in your project directory, please check README for instructions."
46
46
  end
47
47
 
48
48
  # https://stackoverflow.com/a/71192990
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code_manifest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers