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
|
:chicken, :jruby, :lua, :node, :ocaml, :perl, :python, :rbx, :ruby
|
||||||
].freeze
|
].freeze
|
||||||
|
|
||||||
|
CACHE = {}
|
||||||
|
|
||||||
attr_reader :deps, :requirements
|
attr_reader :deps, :requirements
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@ -29,7 +31,7 @@ class DependencyCollector
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add(spec)
|
def add(spec)
|
||||||
case dep = build(spec)
|
case dep = fetch(spec)
|
||||||
when Dependency
|
when Dependency
|
||||||
@deps << dep
|
@deps << dep
|
||||||
when Requirement
|
when Requirement
|
||||||
@ -38,6 +40,18 @@ class DependencyCollector
|
|||||||
dep
|
dep
|
||||||
end
|
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)
|
def build(spec)
|
||||||
spec, tags = case spec
|
spec, tags = case spec
|
||||||
when Hash then destructure_spec_hash(spec)
|
when Hash then destructure_spec_hash(spec)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user