Skip to content

Instantly share code, notes, and snippets.

@inem
Created April 16, 2014 06:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inem/10814522 to your computer and use it in GitHub Desktop.
Save inem/10814522 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'bundler/setup'
require 'chassis'
class Post
attr_accessor :id, :title, :text
end
repo = Chassis::Repo.default
puts repo.empty? Post #=> true
post = Post.new
post.title = 'Such Repos'
post.text = 'Very wow. Much design.'
repo.save post
puts post.id #=> 1
found_post = repo.find Post, post.id
found_post == post #=> true (no difference between objects in memory)
post.title = 'Such updates'
post.text = 'Very easy. Wow'
repo.save post
repo.find(Post, post.id).text #=> 'Very easy. Wow.'
class PostRepo
extend Chassis::Repo::Delegation
end
post = PostRepo.find post.id
post.text #=> 'Very Easy. Wow'
PostRepo.all #=> [post]
# etc
PostRepo.delete post
PostRepo.empty? #=> true
/Projects/my/repositories-experiment > ruby app.rb
true
1
/Users/inem/.rvm/gems/ruby-2.1.0-preview2@my/bundler/gems/chassis-2504d3d17788/lib/chassis/repo/delegation.rb:74:in `backend': undefined method `instance' for Chassis::Repo:Class (NoMethodError)
from /Users/inem/.rvm/gems/ruby-2.1.0-preview2@my/bundler/gems/chassis-2504d3d17788/lib/chassis/repo/delegation.rb:17:in `find'
from app.rb:35:in `<main>'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment