code_manifest 1.1.1 → 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: c5795a2e56a6100341407404bffc27961d9dc4ee72935108ed2acab630f2ecae
4
- data.tar.gz: 1150086276c5a08922197ef9a578558e50cea9bde9760e81ea782baae9fd18af
3
+ metadata.gz: e7020080ba5738c05558a6686645957049173b4cac3de5d4580c6203937d76b8
4
+ data.tar.gz: ca8973cbd93178c7852848ff2e8cd0b76a230dec908ad5c5c9594b0b8b44b6ba
5
5
  SHA512:
6
- metadata.gz: 32b1d5d8b814334eb5e51eac7e4d93c470938c5177fd97a6bb0309ce78b97676b4d03d0e526924881058d998b1f595afd9bf0ef1426c2dd8b4159de05c21fabe
7
- data.tar.gz: 93399d00df69e5a456640ff3af0eff27535f838f1566a088513198c32151e8c71a40362deb2188790d1576ec959ef2b486d59873cd217c6fe57c09b11b59a4ac
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.1'
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,40 +16,39 @@ 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.flatten)
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
49
49
  def load_manifest(file)
50
50
  YAML.load_file(file, aliases: true)
51
51
  rescue ArgumentError
52
- puts YAML.load_file(file)
53
52
  YAML.load_file(file)
54
53
  end
55
54
  end
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.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers