code_manifest 1.1.1 → 1.3.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: c1933fca25570b9db88c444401b2be9ebac5f75550959af0afdcfd0df1c94dd2
4
+ data.tar.gz: a4372d5d3bc2ebbc1e0373636a23e5b974af6a24dc5f64f496a3794715f93809
5
5
  SHA512:
6
- metadata.gz: 32b1d5d8b814334eb5e51eac7e4d93c470938c5177fd97a6bb0309ce78b97676b4d03d0e526924881058d998b1f595afd9bf0ef1426c2dd8b4159de05c21fabe
7
- data.tar.gz: 93399d00df69e5a456640ff3af0eff27535f838f1566a088513198c32151e8c71a40362deb2188790d1576ec959ef2b486d59873cd217c6fe57c09b11b59a4ac
6
+ metadata.gz: c848fc474a9a5f59e3e4d55588d1781b2d4a1834314a4a0bf511779046ae7a020635f233e77502fb32f852d58af817fce07ccd3159b8bedc2d4f58f6543495cd
7
+ data.tar.gz: 52ebaf7b9d59a2546112f9c5180f3add24cc7ae28c5022db26160a27ff0ee4e1f42c09f8ba49cafcaae733d730799d8215f82f8f4e9731fd06a5d95269e8692d
@@ -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
14
- @rules ||= patterns.map do |pattern|
15
- Rule.new(root, pattern)
12
+ def initialize(patterns)
13
+ @rules ||= Array(patterns).map do |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.3.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.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gusto Engineers