File tree Expand file tree Collapse file tree 5 files changed +35
-27
lines changed Expand file tree Collapse file tree 5 files changed +35
-27
lines changed Original file line number Diff line number Diff line change @@ -32,10 +32,14 @@ module Shards
3232 end
3333
3434 def installed ?(loose = false )
35- if loose
36- matching_versions.includes?(resolver.spec(:installed ).version)
35+ if spec = resolver.installed_spec
36+ if loose
37+ matching_versions.includes?(spec.version)
38+ else
39+ version == spec.version
40+ end
3741 else
38- version == resolver.spec( :installed ).version
42+ false
3943 end
4044 end
4145
Original file line number Diff line number Diff line change 11require " ./resolver"
2- require " ../core_ext/file"
2+ # require "../core_ext/file"
33
44module Shards
55 class PathResolver < Resolver
@@ -13,13 +13,17 @@ module Shards
1313 end
1414 end
1515
16- def spec (version = nil )
17- if version == :installed
18- path = File .join(local_path, SPEC_FILENAME )
19- return Spec .from_file(path) if File .exists?(path)
20- end
16+ def installed_spec
17+ return unless installed?
18+
19+ path = File .join(local_path, SPEC_FILENAME )
20+ return Spec .from_file(path) if File .exists?(path)
21+
22+ Spec .from_yaml(" name: #{ dependency.name } \n " )
23+ end
2124
22- super
25+ def installed ?
26+ File .symlink?(install_path)
2327 end
2428
2529 def available_versions
Original file line number Diff line number Diff line change @@ -13,20 +13,20 @@ module Shards
1313 end
1414
1515 def spec (version = nil )
16- if version == :installed
17- path = File .join(install_path, SPEC_FILENAME )
18- if File .exists?(path)
19- Spec .from_file(path)
20- else
21- Spec .from_yaml( " name: #{ dependency.name } \n " )
22- end
23- else
24- Spec .from_yaml(read_spec(version))
25- end
16+ Spec .from_yaml(read_spec( version))
17+ end
18+
19+ def installed_spec
20+ return unless installed?
21+
22+ path = File .join(install_path, SPEC_FILENAME )
23+ return Spec .from_file(path) if File .exists?(path)
24+
25+ Spec .from_yaml( " name: #{ dependency.name } \n " )
2626 end
2727
28- def installed ?(version)
29- spec( :installed ).version == version
28+ def installed ?
29+ File .exists?(install_path)
3030 end
3131
3232 abstract def read_spec (version = nil )
Original file line number Diff line number Diff line change @@ -40,11 +40,11 @@ module Shards
4040 library.install(" 0.1.2" )
4141 assert File .exists?(install_path(" library" , " library.cr" ))
4242 assert File .exists?(install_path(" library" , " shard.yml" ))
43- assert_equal " 0.1.2" , library.spec( :installed ) .version
43+ assert_equal " 0.1.2" , library.installed_spec.not_nil! .version
4444 # assert File.exists?(install_path("library", "LICENSE"))
4545
4646 library.install
47- assert_equal " 0.2.0" , library.spec( :installed ) .version
47+ assert_equal " 0.2.0" , library.installed_spec.not_nil! .version
4848
4949 legacy.install
5050 assert File .exists?(install_path(" legacy" , " legacy.cr" ))
@@ -53,7 +53,7 @@ module Shards
5353 legacy.install(" 1.0.0" )
5454 assert File .exists?(install_path(" legacy" , " legacy.cr" ))
5555 assert File .exists?(install_path(" legacy" , " shard.yml" ))
56- assert_equal " 1.0.0" , legacy.spec( :installed ) .version
56+ assert_equal " 1.0.0" , legacy.installed_spec.not_nil! .version
5757
5858 empty.install # HEAD
5959 assert File .exists?(install_path(" empty" , " empty.cr" ))
Original file line number Diff line number Diff line change @@ -22,14 +22,14 @@ module Shards
2222 library.install
2323 assert File .exists?(install_path(" library" , " library.cr" ))
2424 refute File .exists?(install_path(" library" , " shard.yml" ))
25- assert_equal " 1.2.3" , library.spec( :installed ) .version
25+ assert_equal " 1.2.3" , library.installed_spec.not_nil! .version
2626 end
2727
2828 resolver(" legacy" ).tap do |legacy |
2929 legacy.install
3030 assert File .exists?(install_path(" legacy" , " legacy.cr" ))
3131 refute File .exists?(install_path(" legacy" , " shard.yml" ))
32- assert_empty legacy.spec( :installed ) .version
32+ assert_empty legacy.installed_spec.not_nil! .version
3333 end
3434 end
3535
You can’t perform that action at this time.
0 commit comments