Class: ElmInstall::Base

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/elm_install/base.rb

Overview

This class is the base for the Cache and GitResolver packages.

Direct Known Subclasses

Cache, GitResolver

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Base

Initializes a new base for a cache.

Parameters:

  • options (Hash) (defaults to: {})

    The options



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

def initialize(options = {})
  @options = options
  @cache = {}
  load
end

Instance Attribute Details

#cacheHash (readonly)

Returns The current cache.

Returns:

  • (Hash)

    The current cache



7
8
9
# File 'lib/elm_install/base.rb', line 7

def cache
  @cache
end

Instance Method Details

#directoryString

Returns the path of the directory where the cache is stored.

Returns:

  • (String)

    The path



46
47
48
# File 'lib/elm_install/base.rb', line 46

def directory
  @options[:directory]
end

#fileString

Returns the patch of the cache file.

Returns:

  • (String)

    The path



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

def file
  File.join(directory, @file)
end

#loadvoid

This method returns an undefined value.

Loads a cache from the json file.



30
31
32
33
34
# File 'lib/elm_install/base.rb', line 30

def load
  @cache = JSON.parse(File.read(file))
rescue
  @cache = {}
end

#savevoid

This method returns an undefined value.

Saves the cache into the json file.



23
24
25
# File 'lib/elm_install/base.rb', line 23

def save
  File.binwrite(file, JSON.pretty_generate(@cache))
end