From 14de1eda09a5994a3df186693298f6625a6e917a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szikszai=20Guszt=C3=A1v?= Date: Fri, 15 Sep 2017 10:50:11 +0200 Subject: [PATCH] Cache Elm versions of package versions. Fixes #42 --- lib/elm_install/git_source.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/elm_install/git_source.rb b/lib/elm_install/git_source.rb index b78efe7..13ed7e1 100644 --- a/lib/elm_install/git_source.rb +++ b/lib/elm_install/git_source.rb @@ -68,6 +68,18 @@ def copy_to(version, directory) nil end + Contract String => String + # Returns the supported Elm version the given ref. + # + # @param ref [String] The ref + # + # @return [Array] The version + def elm_version_of(ref) + @@elm_versions ||= {} + @@elm_versions[url] ||= {} + @@elm_versions[url][ref] ||= identifier.elm_version(fetch(ref)) + end + Contract ArrayOf[Solve::Constraint], String => ArrayOf[Semverse::Version] # Returns the available versions for a repository # @@ -101,7 +113,7 @@ def matching_versions(constraints, elm_version) repository .versions .select do |version| - identifier.elm_version(fetch(version.to_s)) == elm_version && + elm_version_of(version.to_s) == elm_version && constraints.all? { |constraint| constraint.satisfies?(version) } end .sort