Class: Resync::ZipPackages
- Inherits:
-
Object
- Object
- Resync::ZipPackages
- Includes:
- Enumerable
- Defined in:
- lib/resync/client/zip_packages.rb
Overview
Lazily retrieves and caches the zip packages for the specified list of resources. The packages are cached to temporary files which are deleted on exit; if they are deleted while the interpreter is running, the behavior is undefined (but bad things are likely to happen).
Instance Method Summary collapse
-
#[](key) ⇒ ZipPackage
Gets the zip package at the specified index, downloading it if necessary.
-
#each ⇒ Object
Lazily iterates the given block for each zip package, downloading as necessary.
-
#initialize(resources) ⇒ ZipPackages
constructor
Creates a new ZipPackages wrapper for the specified list of resources.
-
#package_for(resource) ⇒ ZipPackage
Gets the zip package for the specified resource, downloading it if necessary.
-
#size ⇒ Object
Gets the size of this list of packages.
Constructor Details
#initialize(resources) ⇒ ZipPackages
Creates a new Resync::ZipPackages wrapper for the specified list of resources.
14 15 16 17 |
# File 'lib/resync/client/zip_packages.rb', line 14 def initialize(resources) @resources = resources @packages = {} end |
Instance Method Details
#[](key) ⇒ ZipPackage
Gets the zip package at the specified index, downloading it if necessary.
30 31 32 33 |
# File 'lib/resync/client/zip_packages.rb', line 30 def [](key) resource = @resources[key] package_for(resource) end |
#each ⇒ Object
Lazily iterates the given block for each zip package, downloading as necessary.
45 46 47 48 49 |
# File 'lib/resync/client/zip_packages.rb', line 45 def each @resources.lazy.each do |resource| yield package_for(resource) end end |
#package_for(resource) ⇒ ZipPackage
Gets the zip package for the specified resource, downloading it if necessary.
38 39 40 |
# File 'lib/resync/client/zip_packages.rb', line 38 def package_for(resource) @packages[resource] ||= resource.zip_package end |
#size ⇒ Object
Gets the size of this list of packages.
21 22 23 |
# File 'lib/resync/client/zip_packages.rb', line 21 def size @resources.size end |