Skip to content

Commit 5b3975d

Browse files
committed
Refactor resolvers slightly
1 parent fd7f6bd commit 5b3975d

File tree

3 files changed

+13
-28
lines changed

3 files changed

+13
-28
lines changed

src/resolvers/git.cr

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,23 +41,12 @@ module Shards
4141
end
4242
end
4343

44-
def specs(versions)
45-
specs = {} of String => Spec
46-
47-
versions.each do |version|
48-
refs = git_refs(version)
49-
yaml = capture("git show #{refs}:#{SPEC_FILENAME}")
50-
specs[version] = Spec.from_yaml(yaml).tap { |spec| spec.resolver = self }
51-
rescue Error
52-
end
53-
54-
specs
44+
def spec(version = nil)
45+
Spec.from_yaml(read_spec(version)).tap { |spec| spec.resolver = self }
5546
end
5647

57-
def spec?(version)
58-
refs = git_refs(version)
59-
yaml = capture("git show #{refs}:#{SPEC_FILENAME}")
60-
Spec.from_yaml(yaml)
48+
private def spec?(version)
49+
spec(version)
6150
rescue Error
6251
end
6352

src/resolvers/path.cr

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,10 @@ module Shards
2020
@dependency.path
2121
end
2222

23-
def spec?(version)
24-
spec_path = File.join(local_path, SPEC_FILENAME)
25-
26-
if File.exists?(spec_path)
27-
Spec.from_yaml(File.read(spec_path))
28-
# TODO: fail if the spec isn't the expected version!
29-
end
23+
def spec(version = nil)
24+
spec = Spec.from_yaml(read_spec(version))
25+
spec.resolver = self
26+
spec
3027
end
3128

3229
def installed_spec

src/resolvers/resolver.cr

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ module Shards
1111
def initialize(@dependency)
1212
end
1313

14-
def spec(version = nil)
15-
Spec.from_yaml(read_spec(version)).tap { |spec| spec.resolver = self }
16-
end
17-
1814
def specs(versions)
1915
specs = {} of String => Spec
20-
versions.each { |version| specs[version] = spec(version) }
16+
versions.each do |version|
17+
specs[version] = spec(version)
18+
rescue Error
19+
end
2120
specs
2221
end
2322

@@ -35,7 +34,7 @@ module Shards
3534
end
3635

3736
abstract def read_spec(version = nil)
38-
abstract def spec?(version)
37+
abstract def spec(version)
3938
abstract def available_versions
4039
abstract def install(version = nil)
4140
abstract def installed_commit_hash

0 commit comments

Comments
 (0)