0.0.1 • Published 11 years ago

cstep v0.0.1

Weekly downloads
4
License
BSD
Repository
github
Last release
11 years ago

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"}
0.0.1

11 years ago

0.0.0

11 years ago