Created
April 16, 2014 06:06
-
-
Save inem/10814522 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/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