How to use clay - 10 common examples

To help you get started, we’ve selected a few clay examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Yipit / clay.js / test / unit / issues.js View on Github external
, should = require('should')
, crypto = require('crypto')
, _ = require('underscore')._;

var models = require('clay');
var mock = new models.storage.Mechanism();

models.set_primary_storage(mock);

var Foo = models.declare("Foo", function(it, kind){
    it.has.method('work', function(msg){
        return "foooooooooooooooooo"
    });
});

var Bar = models.declare("Bar", function(it, kind){
    it.has.method('work', function(msg){
        return "baaaaarrrrrrrrrrrrr"
    });
});

vows.describe('Model issues').addBatch({
    'can be declared sequentially': {
        topic: {
            'Foo': Foo,
            'Bar': Bar,
        },
        'and keep their spec sandboxed': function(MODELS){
            MODELS.Foo._meta.name.should.equal('Foo');
            MODELS.Bar._meta.name.should.equal('Bar');
        }
    },
github Yipit / clay.js / test / unit / base.js View on Github external
'Array.prototype.models return unique models': function() {
        var Person = models.declare('Person');
        var p1 = new Person({__id__: 1});
        var p2 = new Person({__id__: 2});
        var p3 = new Person({__id__: 3});

        var p4 = new Person({__id__: 1});
        var p5 = new Person({__id__: 2});
        var p6 = new Person({__id__: 3});


        var People = [];
        People.add(p1);
        People.add(p2);
        People.add(p3);
        People.add(p4);
        People.add(p5);
        People.add(p6);
github Yipit / clay.js / test / unit / issues.js View on Github external
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE. */

var vows = require('vows')
, should = require('should')
, crypto = require('crypto')
, _ = require('underscore')._;

var models = require('clay');
var mock = new models.storage.Mechanism();

models.set_primary_storage(mock);

var Foo = models.declare("Foo", function(it, kind){
    it.has.method('work', function(msg){
        return "foooooooooooooooooo"
    });
});

var Bar = models.declare("Bar", function(it, kind){
    it.has.method('work', function(msg){
        return "baaaaarrrrrrrrrrrrr"
    });
});

vows.describe('Model issues').addBatch({
    'can be declared sequentially': {
        topic: {
            'Foo': Foo,
            'Bar': Bar,
github Yipit / clay.js / test / unit / storage-mechanism.js View on Github external
'when you declare a model, it is possible to specify its store': function(){
        function FakeMechanism (){models.storage.Mechanism.call(this)};
        util.inherits(FakeMechanism, models.storage.Mechanism);

        var fake_mechanism = new FakeMechanism();

        var User = models.declare('User', function (it, kind){
            it.has.field("name", kind.string);
            it.is_stored_with(fake_mechanism)
        });

        assert.deepEqual(fake_mechanism, User._meta.storage);
    },
    'it is possible to set the default storage mechanism': function(){
github Yipit / clay.js / test / unit / storage-mechanism.js View on Github external
'it is possible to set the default storage mechanism': function(){
        function FakeMechanismTwo (){models.storage.Mechanism.call(this)};
        util.inherits(FakeMechanismTwo, models.storage.Mechanism);

        var fake2 = new FakeMechanismTwo();

        models.set_primary_storage(fake2)

        var Build = models.declare('Build', function (it, kind){
            it.has.field("name", kind.string);
        });

        assert.deepEqual(fake2, Build._meta.storage);
    },
    'it defaults to the redis storage mechanism': function(){
github Yipit / clay.js / test / functional / redis_storage.js View on Github external
var vows = require('vows')
, should = require('should')
, async = require('async')
, fs = require('fs')
, events = require('events')
, _ = require('underscore')._
, path = require('path')
, redis = require('redis');

var client = redis.createClient();

var models = require('clay');
var redis_storage = new models.storage.RedisMechanism(client);

var User = models.declare("User", function(it, kind){
    it.has.field("name", kind.string);
    it.has.field("email", kind.email);
    it.has.field("password", kind.hashOf(["name", "email"]));

    it.has.method('greet', function() {
        return [
            "Hello, my name is ", this.name, ", it's nice to meet you"
        ].join('');
    });
    it.validates.uniquenessOf("name");
    it.has.index('email');
    it.is_stored_with(redis_storage);
});

var Build = models.declare("Build", function(it, kind){
    it.has.field("status", kind.numeric);
github Yipit / clay.js / test / unit / fields.js View on Github external
'get the values from a given object for the given keys': function(hasher) {
                var Stub = models.declare("Stub", function(it, kind){
                    it.has.field("name", kind.alphanumeric);
                    it.has.field("id", kind.numeric);
                });

                var stub = new Stub({name: "gabriel", id: 42}, Stub);

                assert.equal(
                    stub._meta.get_key(['name', 'id'], 'some-other-value'),
                    'gabriel|sha1-clay|42|sha1-clay|some-other-value'
                )
            }
        }
github Yipit / clay.js / test / unit / models.js View on Github external
topic: function () {
            return models.declare("Person", function(it, kind){
                it.has.field("username", kind.alphanumeric);
                it.has.field("email_address", kind.email);
                it.has.field("birthdate", kind.datetime);
                it.has.field("created_at", kind.auto);
                it.has.field("zipcode", kind.numeric);
                it.has.field("password", kind.string);

                it.validates.uniquenessOf("username");

                it.validates.presenceOf("username");
                it.validates.presenceOf("email_address");

                it.has.index("username");
                it.has.index("email_address");

                it.has.setter('email', function(address){
github Yipit / clay.js / test / functional / redis_storage.js View on Github external
var User = models.declare("User", function(it, kind){
    it.has.field("name", kind.string);
    it.has.field("email", kind.email);
    it.has.field("password", kind.hashOf(["name", "email"]));

    it.has.method('greet', function() {
        return [
            "Hello, my name is ", this.name, ", it's nice to meet you"
        ].join('');
    });
    it.validates.uniquenessOf("name");
    it.has.index('email');
    it.is_stored_with(redis_storage);
});

var Build = models.declare("Build", function(it, kind){
    it.has.field("status", kind.numeric);
    it.has.field("error", kind.string);
    it.has.field("output", kind.string);
    it.has.field("started_at", kind.auto);
    it.has.field("finished_at", kind.datetime);
    it.has.one("author", User, "builds");
    it.is_stored_with(redis_storage);
});
var BuildInstruction = models.declare("BuildInstruction", function(it, kind){
    it.has.field("name", kind.string);
    it.has.field("repository_address", kind.string);
    it.has.field("build_command", kind.string);

    it.has.many("builds", Build, "instruction");
    it.has.one("owner", User, "created_instructions");
    it.is_stored_with(redis_storage);
github Yipit / clay.js / test / functional / redis_storage.js View on Github external
});
    it.validates.uniquenessOf("name");
    it.has.index('email');
    it.is_stored_with(redis_storage);
});

var Build = models.declare("Build", function(it, kind){
    it.has.field("status", kind.numeric);
    it.has.field("error", kind.string);
    it.has.field("output", kind.string);
    it.has.field("started_at", kind.auto);
    it.has.field("finished_at", kind.datetime);
    it.has.one("author", User, "builds");
    it.is_stored_with(redis_storage);
});
var BuildInstruction = models.declare("BuildInstruction", function(it, kind){
    it.has.field("name", kind.string);
    it.has.field("repository_address", kind.string);
    it.has.field("build_command", kind.string);

    it.has.many("builds", Build, "instruction");
    it.has.one("owner", User, "created_instructions");
    it.is_stored_with(redis_storage);
});

function clear_redis(callback) {
    var topic = this;

    async.waterfall([
        function wait_for_lock(callback) {
            var counter = 0;
            var handle = setInterval(function(){