Cache and reuse Dependency objects
This commit is contained in:
parent
1981e78eb2
commit
74eb25df81
@ -21,6 +21,8 @@ class DependencyCollector
|
||||
:chicken, :jruby, :lua, :node, :ocaml, :perl, :python, :rbx, :ruby
|
||||
].freeze
|
||||
|
||||
CACHE = {}
|
||||
|
||||
attr_reader :deps, :requirements
|
||||
|
||||
def initialize
|
||||
@ -29,7 +31,7 @@ class DependencyCollector
|
||||
end
|
||||
|
||||
def add(spec)
|
||||
case dep = build(spec)
|
||||
case dep = fetch(spec)
|
||||
when Dependency
|
||||
@deps << dep
|
||||
when Requirement
|
||||
@ -38,6 +40,18 @@ class DependencyCollector
|
||||
dep
|
||||
end
|
||||
|
||||
def fetch(spec)
|
||||
CACHE.fetch(cache_key(spec)) { |key| CACHE[key] = build(spec) }
|
||||
end
|
||||
|
||||
def cache_key(spec)
|
||||
if Resource === spec && spec.download_strategy == CurlDownloadStrategy
|
||||
File.extname(spec.url)
|
||||
else
|
||||
spec
|
||||
end
|
||||
end
|
||||
|
||||
def build(spec)
|
||||
spec, tags = case spec
|
||||
when Hash then destructure_spec_hash(spec)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user