Permalink
Browse files

Improve client documentation

  • Loading branch information...
1 parent 1a584ca commit 1c60d9a9e52eebfffb2d5158246e52dd01ac20cf @wdavidw committed Mar 4, 2012
Showing with 248 additions and 190 deletions.
  1. +69 −11 lib/Client.coffee
  2. +5 −5 test/all.coffee
  3. +5 −5 test/count.coffee
  4. +5 −5 test/create.coffee
  5. +5 −5 test/create_validation.coffee
  6. +5 −5 test/exists.coffee
  7. +5 −5 test/get.coffee
  8. +6 −6 test/hash.coffee
  9. +127 −127 test/id.coffee
  10. +5 −5 test/list.coffee
  11. +6 −6 test/remove.coffee
  12. +5 −5 test/update.coffee
View
@@ -3,8 +3,38 @@ redis = require 'redis'
Schema = require './Schema'
Records = require './Records'
+###
+Ron client
+==========
+The client wraps a redis connection and provides access to records definition
+and manipulation.
+
+Internall, Ron rely on the [Redis client for Node.js](https://github.com/mranney/node_redis).
+
+###
module.exports = class Client
+ ###
+
+ `ron([options])` Client creation
+ --------------------------------
+
+ `options` Options properties include:
+
+ * `name` A namespace for the application, all keys with be prefixed with "#{name}:". Default to "ron"
+ * `redis` Provide an existing instance in case you don't want a new one to be created.
+ * `redis_host` Redis database hostname.
+ * `redis_port` Redis database port.
+ * `redis_password` Redis databse password.
+ * `redis_database` Integer defining the redis database.
+
+ Basic example:
+ ron = require 'ron'
+ client = ron
+ redis_host: '127.0.0.1'
+ redis_port: 6379
+
+ ###
constructor: (options = {}) ->
@options = options
@name = options.name or 'ron'
@@ -16,21 +46,49 @@ module.exports = class Client
@redis = redis.createClient options.redis_port ? 6379, options.redis_host ? '127.0.0.1'
@redis.auth options.redis_password if options.redis_password?
@redis.select options.redis_database if options.redis_database?
+ ###
+
+ `get(schema)` Records definition and access
+ -------------------------------------------
+ Return a records instance. If the `schema` argument is an object, a new
+ instance will be created overwriting any previously defined instance
+ with the same name.
- # schema: (options) ->
- # name = if typeof options is 'string' then options else options.name
- # @schemas[name] = new Schema @, options
- # @records[name] = new Records @, @schemas[name]
- # @schemas[name]
+ `schema` An object defining a new schema or a string referencing a schema name.
- get: (options) ->
- # @records[name]
- name = if typeof options is 'string' then options else options.name
- @records[name] = new Records @, options if typeof options isnt 'string' or not @records[name]?
- @records[name]
+ Define a record from a object:
+ client.get
+ name: 'users'
+ properties:
+ user_id: identifier: true
+ username: unique: true
+ email: index: true
+ Define a record from function calls:
+ Users = client.get 'users'
+ Users.identifier 'user_id'
+ Users.unique 'username'
+ Users.index 'email'
+
+ ###
+ get: (schema) ->
+ name = if typeof schema is 'string' then schema else schema.name
+ @records[name] = new Records @, schema if typeof schema isnt 'string' or not @records[name]?
+ @records[name]
+ ###
+
+ `quit(callback)` Quit
+ ---------------------
+ Destroy the redis connection.
+
+ `callback` Received parameters are:
+
+ * `err` Error object if any.
+ * `status` Status provided by the redis driver
+
+ ###
quit: (callback) ->
@redis.quit (err, status) ->
return unless callback
return callback err if err
- callback null, status if callback
+ callback null, status if callback
View
@@ -2,15 +2,15 @@
should = require 'should'
try config = require '../conf/test' catch e
-Ron = require '../index'
+ron = require '../index'
describe 'all', ->
- ron = Users = null
+ client = Users = null
before (next) ->
- ron = Ron config
- Users = ron.get
+ client = ron config
+ Users = client.get
name: 'users'
properties:
user_id: identifier: true
@@ -22,7 +22,7 @@ describe 'all', ->
Users.clear next
after (next) ->
- ron.quit next
+ client.quit next
it 'shall create 2 users and list them', (next) ->
Users.create [
View
@@ -2,15 +2,15 @@
should = require 'should'
try config = require '../conf/test' catch e
-Ron = require '../index'
+ron = require '../index'
describe 'count', ->
- ron = Users = null
+ client = Users = null
before (next) ->
- ron = Ron config
- Users = ron.get 'users'
+ client = ron config
+ Users = client.get 'users'
Users.identifier 'user_id'
Users.unique 'username'
Users.index 'email'
@@ -20,7 +20,7 @@ describe 'count', ->
Users.clear next
after (next) ->
- ron.quit next
+ client.quit next
it 'Test count', (next) ->
Users.create [
View
@@ -2,15 +2,15 @@
should = require 'should'
try config = require '../conf/test' catch e
-Ron = require '../index'
+ron = require '../index'
describe 'create', ->
- ron = Users = null
+ client = Users = null
before (next) ->
- ron = Ron config
- Users = ron.get
+ client = ron config
+ Users = client.get
name: 'users'
properties:
user_id: identifier: true
@@ -22,7 +22,7 @@ describe 'create', ->
Users.clear next
after (next) ->
- ron.quit next
+ client.quit next
it 'Test create # one user', (next) ->
Users.create
@@ -2,15 +2,15 @@
should = require 'should'
try config = require '../conf/test' catch e
-Ron = require '../index'
+ron = require '../index'
describe 'create_validation', ->
- ron = Users = null
+ client = Users = null
before (next) ->
- ron = Ron config
- Users = ron.get
+ client = ron config
+ Users = client.get
name: 'users'
properties:
user_id: identifier: true
@@ -22,7 +22,7 @@ describe 'create_validation', ->
Users.clear next
after (next) ->
- ron.quit next
+ client.quit next
it 'Test create validate # email with record', (next) ->
Users.create
View
@@ -2,7 +2,7 @@
should = require 'should'
try config = require '../conf/test' catch e
-Ron = require '../index'
+ron = require '../index'
describe 'exists', ->
@@ -19,11 +19,11 @@ describe 'exists', ->
should.ifError err
callback(null, users)
- ron = Users = null
+ client = Users = null
before (next) ->
- ron = Ron config
- Users = ron.get
+ client = ron config
+ Users = client.get
name: 'users'
properties:
user_id: identifier: true
@@ -35,7 +35,7 @@ describe 'exists', ->
Users.clear next
after (next) ->
- ron.quit next
+ client.quit next
it 'Test exists # true # identifier', (next) ->
create (err, users) ->
View
@@ -2,15 +2,15 @@
should = require 'should'
try config = require '../conf/test' catch e
-Ron = require '../index'
+ron = require '../index'
describe 'get', ->
- ron = Users = null
+ client = Users = null
before (next) ->
- ron = Ron config
- Users = ron.get
+ client = ron config
+ Users = client.get
name: 'users'
properties:
user_id: identifier: true
@@ -22,7 +22,7 @@ describe 'get', ->
Users.clear next
after (next) ->
- ron.quit next
+ client.quit next
it 'Test get # identifier', (next) ->
Users.create
View
@@ -2,26 +2,26 @@
should = require 'should'
try config = require '../conf/test' catch e
-Ron = require '../index'
+ron = require '../index'
describe 'client', ->
- ron = null
+ client = null
before (next) ->
- ron = Ron config
+ client = ron config
next()
after (next) ->
- ron.quit next
+ client.quit next
it 'init', (next) ->
next()
it 'should hash a string', (next) ->
- ron.get('users').hash('1').should.eql '356a192b7913b04c54574d18c28d46e6395428ab'
+ client.get('users').hash('1').should.eql '356a192b7913b04c54574d18c28d46e6395428ab'
next()
it 'should hash a number', (next) ->
- ron.get('users').hash(1).should.eql '356a192b7913b04c54574d18c28d46e6395428ab'
+ client.get('users').hash(1).should.eql '356a192b7913b04c54574d18c28d46e6395428ab'
next()
Oops, something went wrong.

0 comments on commit 1c60d9a

Please sign in to comment.