Class: Resync::ZipPackages

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(resources) ⇒ ZipPackages

Creates a new Resync::ZipPackages wrapper for the specified list of resources.

Parameters:

  • The list of resources to get zip packages for.



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.

Returns:

  • the zip package for the resource at the specified index in the underlying array.



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.

Parameters:

  • The block to iterate



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.

Returns:

  • the package for the resource



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.

Returns:

  • the size of the underlying array.



21
22
23
# File 'lib/resync/client/zip_packages.rb', line 21

def size
  @resources.size
end