Skip to content

Commit c3eaf75

Browse files
authored
Make CodeManifest.load_manifes publict (#5)
* Make CodeManifest.load_manifes publict * Bump * Fix * Review tweaks
1 parent 3fb9371 commit c3eaf75

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

Gemfile.lock

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
PATH
22
remote: .
33
specs:
4-
code_manifest (1.6.1)
4+
code_manifest (1.7.0)
5+
psych (>= 4.0.0)
56

67
GEM
78
remote: https://rubygems.org/
89
specs:
910
diff-lcs (1.5.0)
11+
psych (5.1.2)
12+
stringio
1013
rake (13.0.6)
1114
rspec (3.11.0)
1215
rspec-core (~> 3.11.0)
@@ -21,6 +24,7 @@ GEM
2124
diff-lcs (>= 1.2.0, < 2.0)
2225
rspec-support (~> 3.11.0)
2326
rspec-support (3.11.1)
27+
stringio (3.1.0)
2428

2529
PLATFORMS
2630
arm64-darwin-21

code_manifest.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
2121
spec.require_paths = ["lib"]
2222

2323
# Uncomment to register a new dependency of your gem
24-
# spec.add_dependency "example-gem", "~> 1.0"
24+
spec.add_dependency "psych", ">= 4.0.0"
2525

2626
spec.add_development_dependency 'rspec', '~> 3.0'
2727

lib/code_manifest.rb

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,20 @@ def root(start_path: Dir.pwd, reset: false)
2121
@root ||= find_root(start_path)
2222
end
2323

24-
private
24+
def load_file(manifest_file)
25+
YAML.load_file(manifest_file, aliases: true).each_with_object({}) do |(name, patterns), collection|
26+
next unless name.match?(KEY_PATTERN)
2527

26-
def manifests
27-
@manifests ||= begin
28-
manifest_file = root.join(MANIFEST_FILE)
28+
raise ArgumentError, "#{name} defined multiple times in #{manifest_file}" if collection.key?(name)
2929

30-
load_manifest(manifest_file).each_with_object({}) do |(name, patterns), collection|
31-
next unless name.match?(KEY_PATTERN)
30+
collection[name] = Manifest.new(patterns.flatten)
31+
end
32+
end
3233

33-
raise ArgumentError, "#{name} defined multiple times in #{MANIFEST_FILE}" if collection.key?(name)
34+
private
3435

35-
collection[name] = Manifest.new(patterns.flatten)
36-
end
37-
end
36+
def manifests
37+
@manifests ||= load_file(root.join(MANIFEST_FILE))
3838
end
3939

4040
def find_root(path)
@@ -44,12 +44,5 @@ def find_root(path)
4444

4545
raise "#{MANIFEST_FILE} was not found in your project directory, please check README for instructions."
4646
end
47-
48-
# https://stackoverflow.com/a/71192990
49-
def load_manifest(file)
50-
YAML.load_file(file, aliases: true)
51-
rescue ArgumentError
52-
YAML.load_file(file)
53-
end
5447
end
5548
end

lib/code_manifest/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module CodeManifest
4-
VERSION = '1.6.1'
4+
VERSION = '1.7.0'
55
end

0 commit comments

Comments
 (0)