Class: Fig::PackageCache

Inherits:
Object
  • Object
show all
Defined in:
lib/fig/package_cache.rb

Overview

Simple double-level (name, version) cache of Packages.

Instance Method Summary collapse

Constructor Details

#initializePackageCache

Returns a new instance of PackageCache.


7
8
9
# File 'lib/fig/package_cache.rb', line 7

def initialize()
  @packages = {}
end

Instance Method Details

#add_package(package) ⇒ Object


11
12
13
14
15
16
17
18
19
20
21
# File 'lib/fig/package_cache.rb', line 11

def add_package(package)
  versions = @packages[package.name]
  if not versions
    versions = {}
    @packages[package.name] = versions
  end

  versions[package.version] = package

  return
end

#get_any_version_of_package(name) ⇒ Object

Don't care which one, just gimme.


31
32
33
34
35
36
# File 'lib/fig/package_cache.rb', line 31

def get_any_version_of_package(name)
  versions = @packages[name]
  return if not versions

  return versions.values.first()
end

#get_package(name, version) ⇒ Object


23
24
25
26
27
28
# File 'lib/fig/package_cache.rb', line 23

def get_package(name, version)
  versions = @packages[name]
  return if not versions

  return versions[version]
end

#remove_package(name, version) ⇒ Object


38
39
40
41
42
43
44
45
# File 'lib/fig/package_cache.rb', line 38

def remove_package(name, version)
  versions = @packages[name]
  return if not versions

  versions.delete(version)

  return
end