Storage (name opt , fs, configPath, options opt )

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 opt , fs, configPath, options opt )

Parameters:
Name Type Attributes Description
name String <optional>

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.

options Object <optional>

Storage options.

Properties
Name Type Attributes Default Description
lodashPath Boolean <optional>
false

Set true to treat name as a lodash path.

disableCache Boolean <optional>
false

Set true to disable json object cache.

disableCacheByFile Boolean <optional>
false

Set true to cleanup cache for every fs change.

sorted Boolean <optional>
false

Set true to write sorted json.

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

Methods

createProxy () → {Object}

Creates a proxy object.

Returns:
Object -

proxy.

createStorage (path) → { Storage }

Create a child storage.

Parameters:
Name Type Description
path String

relative path of the key to create a new storage. Some paths need to be escaped. Eg: ["dotted.path"]

Returns:
Storage -

Returns a new Storage.

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

getPath (path) → {*}

Get a stored value from a lodash path

Parameters:
Name Type Description
path String

The path under which the value is stored.

Returns:
* -

The stored value. Any JSON valid type could be returned

merge (defaults) → {*}

Parameters:
Name Type Description
defaults Object

Key-value object to store.

Returns:
* -

val Returns the merged 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.

setPath (path, val) → {*}

Assign a lodash path to a value and schedule a save.

Parameters:
Name Type Description
path 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.