Skip to content

yamadapc/mongoose-access-gen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongoose-access-gen

A little mongoose-plugin for generating array property adders and deleters

Getting Started

Install the module with: npm install mongoose-access-gen

[...]

var access = require('mongoose-access-gen');

var ComedianSchema = new Schema({
  jokes   : [{ type: String  }],
  laughing:  { type: Boolean }
});

ComedianSchema.plugin(access);

var Comedian = mongoose.model('Comedian', ComedianSchema),
    comedian = new Comedian({
      jokes: ['A haskell programmer walks into a bar (...)']
    });

// Works with arrays
comedian._genAdd('jokes') ('I\'m a C programmer (...)');
comedian._genDel('jokes') ('A haskell programmer walks into a bar (...)');

// And values
comedian._genSet('laughing') (true);

// And it automatically generates useless methods
var funniest_joke = 'Objective C++ (that\'s all)';

comedian.addJoke(funniest_joke);
comedian.jokes.indexOf(funniest_joke) !== -1 // true

comedian.delJoke(funniest_joke);
comedian.jokes.indexOf(funniest_joke)        // -1

comedian.setLaughing(true);
comedian.laughing                            // true

comedian.unsetLaughing();
comedian.laughing                            // undefined

[...]

License

Copyright (c) 2013 Yamada. Licensed under the MIT license.

Donations

Would you like to buy me a beer? Send bitcoin to 3JjxJydvoJjTrhLL86LGMc8cNB16pTAF3y

About

A really stupid solution for a non-problem: An object's array property access style

Resources

License

Stars

Watchers

Forks

Packages

No packages published