Class: ElmInstall::Cache

Inherits:
Base
  • Object
show all
Defined in:
lib/elm_install/cache.rb

Overview

This class is responsible for maintaining a cache of all the repositories their versions and their dependencies.

By default the clones of the repositories live in the users home directory (~/.elm-install), this can be changed with the ‘directory` option.

Instance Attribute Summary

Attributes inherited from Base

#cache

Instance Method Summary collapse

Methods inherited from Base

#directory, #file, #load, #save

Constructor Details

#initialize(options) ⇒ Cache

Returns a new instance of Cache.



11
12
13
14
# File 'lib/elm_install/cache.rb', line 11

def initialize(options)
  @file = 'cache.json'
  super options
end

Instance Method Details

#dependency(package, version, constraint) ⇒ Object

Adds a new dependency to the cache for a given package & version combination.



18
19
20
21
# File 'lib/elm_install/cache.rb', line 18

def dependency(package, version, constraint)
  ensure_package version
  @cache[package][version] << constraint
end

#ensure_package(package) ⇒ Object

Ensures that a package exists in the cache.



30
31
32
# File 'lib/elm_install/cache.rb', line 30

def ensure_package(package)
  @cache[package] ||= {}
end

#ensure_version(package, version) ⇒ Object

Ensures that a package & version combination exists in the cache.



24
25
26
27
# File 'lib/elm_install/cache.rb', line 24

def ensure_version(package, version)
  ensure_package package
  @cache[package][version] ||= []
end