Sha256: dc8f76b454b30b2132028bf3acaf378cb96ad228e84f629ab39ceccad2888158

Contents?: true

Size: 1.44 KB

Versions: 7

Compression:

Stored size: 1.44 KB

Contents

Mootools ORM (like ActiveResource or Jester).

Readme below may be a little bit outdated. To be rewritten.




  var Post = new Resource("Post")
  Post.find("all", function(p) {
    p.title = "All your base are belong to us"
    p.save
  })

  p = new Post({title: "Hello world"}).save
  p.errors #=> {something}

This thing is rails & merb-oriented
As they are supported out of the box:

Merb, with Merb.disable(:json) & ActiveRecord:

  provides :json
  display @post, :only => [:title, :body, :created_at, :id], :include => {:comments => {:only => [:body, :created_at, 
  :id]}}

Merb without ActiveRecord:

  provides :json
  display @post #cant control anything here, associations not included

Rails:

  respond_to do |f|
    f.json do
      @post.to_json, :only => [:title, :body, :created_at, :id], :include => {:comments => {:only => [:body, 
      :created_at, :id]}}
    end
  end

So with that backend we can do this: 

  new Resource("Post", {
    associations: {
      comments: ["Comment", {prefix: true}] #setting autoprefix on 
    } 
  })

  Post.find(1).chain(function(post) {
    post.title = "defaced"
    post.comments.each(function(comment) {
      comment.destroy() # DELETE /posts/1/comments/n
    })
    post.save().chain(function(result) {
      if (!result) {
        alert(post.errors) # => ["Title is too short"]
      } else {
        alert("Ha ha ha... You are on your way to destruction")
      }
    }) # PUT /posts/1/ title=defaced
  })

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
lsd_rails-0.1.6 Packages/mootools-resource/README.md
lsd_rails-0.1.5 Packages/mootools-resource/README.md
lsd_rails-0.1.4 Packages/mootools-resource/README.md
lsd_rails-0.1.3 Packages/mootools-resource/README.md
lsd_rails-0.1.2 Packages/mootools-resource/README.md
lsd_rails-0.1.1 Packages/mootools-resource/README.md
lsd_rails-0.1 Packages/mootools-resource/README.md