Class: ElmInstall::Base
- Inherits:
-
Object
- Object
- ElmInstall::Base
- 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
Instance Attribute Summary collapse
-
#cache ⇒ Hash
readonly
The current cache.
Instance Method Summary collapse
-
#directory ⇒ String
Returns the path of the directory where the cache is stored.
-
#file ⇒ String
Returns the patch of the cache file.
-
#initialize(options = {}) ⇒ Base
constructor
Initializes a new base for a cache.
-
#load ⇒ void
Loads a cache from the json file.
-
#save ⇒ void
Saves the cache into the json file.
Constructor Details
#initialize(options = {}) ⇒ Base
Initializes a new base for a cache.
14 15 16 17 18 |
# File 'lib/elm_install/base.rb', line 14 def initialize( = {}) @options = @cache = {} load end |
Instance Attribute Details
#cache ⇒ Hash (readonly)
Returns The current cache.
7 8 9 |
# File 'lib/elm_install/base.rb', line 7 def cache @cache end |
Instance Method Details
#directory ⇒ String
Returns the path of the directory where the cache is stored.
46 47 48 |
# File 'lib/elm_install/base.rb', line 46 def directory @options[:directory] end |
#file ⇒ String
Returns the patch of the cache file.
39 40 41 |
# File 'lib/elm_install/base.rb', line 39 def file File.join(directory, @file) end |
#load ⇒ void
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 |
#save ⇒ void
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 |