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

Returns a new instance of Base.



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

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

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



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

def cache
  @cache
end

Instance Method Details

#directoryObject

Returns the directory where the cache is stored.



33
34
35
# File 'lib/elm_install/base.rb', line 33

def directory
  @options[:directory]
end

#fileObject



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

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

#loadObject

Loads a cache from the json file.



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

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

#saveObject

Saves the cache into the json file.



17
18
19
# File 'lib/elm_install/base.rb', line 17

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