Class: Resync::Client::Zip::ZipPackages
- Inherits:
-
Object
- Object
- Resync::Client::Zip::ZipPackages
- Includes:
- Enumerable
- Defined in:
- lib/resync/client/zip/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 {|ZipPackage| ... } ⇒ Object
Lazily iterates the given block for each zip package, downloading as necessary.
-
#force ⇒ Array<ZipPackage>
(also: #to_ary)
Eagerly gets the zip package for each resource, 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::Client::Zip::ZipPackages wrapper for the specified list of resources.
20 21 22 23 |
# File 'lib/resync/client/zip/zip_packages.rb', line 20 def initialize(resources) @resources = resources @packages = {} end |
Instance Method Details
#[](key) ⇒ ZipPackage
Gets the zip package at the specified index, downloading it if necessary.
36 37 38 39 |
# File 'lib/resync/client/zip/zip_packages.rb', line 36 def [](key) resource = @resources[key] package_for(resource) end |
#each {|ZipPackage| ... } ⇒ Object
Lazily iterates the given block for each zip package, downloading as necessary.
51 52 53 54 55 |
# File 'lib/resync/client/zip/zip_packages.rb', line 51 def each @resources.lazy.each do |resource| yield package_for(resource) end end |
#force ⇒ Array<ZipPackage> Also known as: to_ary
Eagerly gets the zip package for each resource, downloading as necessary. (For compatbility with Enumerator::Lazy#flat_map)
60 61 62 |
# File 'lib/resync/client/zip/zip_packages.rb', line 60 def force @resources.map { |r| package_for(r) }.to_a end |
#package_for(resource) ⇒ ZipPackage
Gets the zip package for the specified resource, downloading it if necessary.
44 45 46 |
# File 'lib/resync/client/zip/zip_packages.rb', line 44 def package_for(resource) @packages[resource] ||= resource.zip_package end |
#size ⇒ Object
Gets the size of this list of packages.
27 28 29 |
# File 'lib/resync/client/zip/zip_packages.rb', line 27 def size @resources.size end |