cstep

Usage

npm install cstep
6 downloads in the last week
25 downloads in the last month

Flow-control library used for coffeescript classes

Usage

cstep = require "cstep"

class Config

  ###
    Function: Constructor

    Parameters:
      source - source of the configuration file

  ###

  constructor: (@source) ->

  ###
    Function: load

    Loads the configuration file

    Parameters:

    next - called when load is complete
  ###

  load: cstep (next) ->
    fs.readFile @source, (err, content) =>
      @_content = JSON.parse content
      next()

  ###
    Function: set

    sets a value to the configuration file

    Parameters:

    next - called when set is complete (used mostly for cstep)
  ###

  set: cstep (key, value, next) ->
    @_content[key] = value
    next()

  ###
    Function: save

    Parameters:

    next - called when save is complete
  ###

  save: cstep (next) ->
    fs.writeFile @source, JSON.stringify(@_content), next

Using Config.coffee

config = new Config __dirname + "/config.json"
config.load().set("hello", "world").save () ->
  #successfully saved {"hello":"world"}
npm loves you