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

Initializes a cache with the given options.

Parameters:

  • options (Hash)

    The options



14
15
16
17
# File 'lib/elm_install/cache.rb', line 14

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

Instance Method Details

#dependency(package, version, constraint) ⇒ Array

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

Parameters:

  • package (String)

    The url of the package

  • version (String)

    The semver version (1.0.0 or 1.0.0+master)

  • constraint (Array)

    The constraint [“pacakge”, “<= 1.0.0”]

Returns:

  • (Array)

    The dependencies of the package & version combination



27
28
29
30
# File 'lib/elm_install/cache.rb', line 27

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

#ensure_package(package) ⇒ Hash

Ensures that a package exists in the cache.

Parameters:

  • package (String)

    The url of the package

Returns:

  • (Hash)

    The dependency hash of the package



48
49
50
# File 'lib/elm_install/cache.rb', line 48

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

#ensure_version(package, version) ⇒ Array

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

Parameters:

  • package (String)

    The url of the package

  • version (String)

    The semver version (1.0.0 or 1.0.0+master)

Returns:

  • (Array)

    The dependencies of the package & version combination



38
39
40
41
# File 'lib/elm_install/cache.rb', line 38

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