Storage(name, fs, configPath)

Storage instances handle a json file where Generator authors can store data.

The Generator class instantiate the storage named config by default.

new Storage(name, fs, configPath)

Parameters:
Name Type Description
name String

The name of the new storage (this is a namespace)

fs mem-fs-editor

A mem-fs editor instance

configPath String

The filepath used as a storage.

Example
class extend Generator {
  writing: function() {
    this.config.set('coffeescript', false);
  }
}

Methods

defaults(defaults) → {*}

Setup the store with defaults value and schedule a save. If keys already exist, the initial value is kept.

Parameters:
Name Type Description
defaults Object

Key-value object to store.

Returns:
* -

val Returns the merged options.

delete(key)

Delete a key from the store and schedule a save.

Parameters:
Name Type Description
key String

The key under which the value is stored.

get(key) → {*}

Get a stored value

Parameters:
Name Type Description
key String

The key under which the value is stored.

Returns:
* -

The stored value. Any JSON valid type could be returned

getAll() → {Object}

Get all the stored values

Returns:
Object -

key-value object

save()

Save a new object of values

set(key, val) → {*}

Assign a key to a value and schedule a save.

Parameters:
Name Type Description
key String

The key under which the value is stored

val *

Any valid JSON type value (String, Number, Array, Object).

Returns:
* -

val Whatever was passed in as val.