Module: Pione::Package::PackageCache

Defined in:
lib/pione/package/package-cache.rb

Overview

PackageCache is cache mechanism for PIONE package. Cache makes both of PPG package for sharing and directory package for reference.

Class Method Summary collapse

Class Method Details

.cache(location) ⇒ Object

Cache PPG package and directory package on the location. This method returns directory cache location. If you want to PPG archive cache location, use #ppg(digest).



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/pione/package/package-cache.rb', line 10

def cache(location)
  if location.directory?
    # if it is directory location, make a PPG archive and expand it
    ppg_location = create_ppg_cache_from_directory(location)
    return create_directory_cache(ppg_location)
  else
    # if it is ppg location, copy a PPG archive and expand it
    if /\.ppg$/i.match(location.basename)
      ppg_location = create_ppg_cache_from_ppg(location)
      return create_directory_cache(ppg_location)
    else
      raise InvalidPackage.new("The location \"%s\" is not PPG archive." % location.address)
    end
  end
end

.directory_cache(digest) ⇒ Object

Find directory cache location by the digest.



46
47
48
49
# File 'lib/pione/package/package-cache.rb', line 46

def directory_cache(digest)
  location = Global.directory_package_cache_directory + digest
  return location.exist? ? location : nil
end

.exist?(digest) ⇒ Boolean

Return true cache that has the digest exists

Returns:

  • (Boolean)


27
28
29
# File 'lib/pione/package/package-cache.rb', line 27

def exist?(digest)
  ppg_cache(digest) and directory_cache(digest)
end

.ppg_cache(digest) ⇒ Object

Find PPG cache location by the digest.



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/pione/package/package-cache.rb', line 32

def ppg_cache(digest)
  Global.ppg_cache_directory.entries.each do |entry|
    begin
      if digest == PackageFilename.parse(entry.basename).digest
        return entry
      end
    rescue InvalidPackageFilename
      next
    end
  end
  return nil
end