code_manifest 1.1.1 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/code_manifest/manifest.rb +13 -9
- data/lib/code_manifest/version.rb +1 -1
- data/lib/code_manifest.rb +14 -15
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e7020080ba5738c05558a6686645957049173b4cac3de5d4580c6203937d76b8
|
4
|
+
data.tar.gz: ca8973cbd93178c7852848ff2e8cd0b76a230dec908ad5c5c9594b0b8b44b6ba
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 :
|
10
|
+
attr_reader :rules
|
11
11
|
|
12
|
-
def initialize(
|
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
|
32
|
-
|
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
|
-
|
62
|
+
|
63
|
+
pathname.relative_path_from(CodeManifest.root).to_s
|
60
64
|
end.compact
|
61
65
|
end
|
62
66
|
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
|
-
|
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 =
|
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 #{
|
33
|
+
raise ArgumentError, "#{name} defined multiple times in #{MANIFEST_FILE}" if collection.key?(name)
|
35
34
|
|
36
|
-
collection[name] = Manifest.new(
|
35
|
+
collection[name] = Manifest.new(patterns.flatten)
|
37
36
|
end
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
41
|
-
def
|
42
|
-
Pathname.new(
|
43
|
-
|
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
|