Skip to content

ReclaimSoftware/rs-model

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Yet another model framework

Build Status

RSModel ∩ Backbone.Model

get, set
.id
constructor, initialize

TODO:

isValid, validate
has, clone, toJSON
keys,values,pairs,invert,pick,omit
url

Singular, Plural

model.get_singular()  # Default: snake_case(class name)
model.get_plural()    # Default: singular + "s"

class Goose
  @plural = "geese"

Storage

All key parts are joined by ":".

[plural, id] -> JSON

TODO:

[plural, id, association, other_id] -> empty
[singular + "_revs", id, rev_id]    -> JSON

Misc

model.path()"/#{plural}/#{id}"

Model.init

Model.init(app)           # checks app.dir/models/*, sets the following
Model.classes             # {'FooBar': FooBar}
Model.classes_by_plural   # {'foo_bars': FooBar}

Model.middleware

Model.middleware()

If all of

  • req.method is GET
  • req.params contains an id matching /^[a-zA-Z0-9_-]+$/
  • req.url starts with /plural/ for a known model

...then fetch the model.

If the model exists, set req.singular to the model.

If not, res.render '404' and don't call next().

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published