sfeley / candy Goto Github PK
View Code? Open in Web Editor NEWTransparent persistence for MongoDB
License: Other
Transparent persistence for MongoDB
License: Other
Link to google groups is http://groups.google.com/group/candy-users/
Doing this:
u = User.new
p = Payment.embed
p.date = Time.now
p.amount = 5.00
u.payment = p
...results in a Payment collection being made and the Payment record going into it, where it will hang around as a duplicate of the one the User has.
This is not right, and it's what the .embed
method was supposed to be for. Make sure initializing with that method never saves anything to the DB.
ruby-1.9.1-p378 > c = Person.name('Bob Smith')
ArgumentError: wrong number of arguments(1 for 0)
from (irb):5:in `name'
from (irb):5
from /Volumes/seley01/Users/steve/.rvm/rubies/ruby-1.9.1-p378/bin/irb:17:in `<main>'
While working on TT:
before(:each) do
# We don't care about the full OAuth setup complexity
@token = stub("an OAuth access token", token: "StubbyToken", secret: "StubbySecret")
@this.token = @token
end
makes:
1)
SystemStackError in 'User OAuth access remembers its token'
stack level too deep
/Users/steve/.rvm/gems/ruby-1.9.1-p378/gems/candy-0.1.0/lib/candy/wrapper.rb:58:in `each'
/Users/steve/.rvm/gems/ruby-1.9.1-p378/gems/candy-0.1.0/lib/candy/wrapper.rb:58:in `wrap_hash'
/Users/steve/.rvm/gems/ruby-1.9.1-p378/gems/candy-0.1.0/lib/candy/wrapper.rb:35:in `wrap'
/Users/steve/.rvm/gems/ruby-1.9.1-p378/gems/candy-0.1.0/lib/candy/wrapper.rb:75:in `block in wrap_object'
/Users/steve/.rvm/gems/ruby-1.9.1-p378/gems/candy-0.1.0/lib/candy/wrapper.rb:72:in `each'
/Users/steve/.rvm/gems/ruby-1.9.1-p378/gems/candy-0.1.0/lib/candy/wrapper.rb:72:in `wrap_object'
/Users/steve/.rvm/gems/ruby-1.9.1-p378/gems/candy-0.1.0/lib/candy/wrapper.rb:46:in `wrap'
/Users/steve/.rvm/gems/ruby-1.9.1-p378/gems/candy-0.1.0/lib/candy/wrapper.rb:75:in `block in wrap_object'
/Users/steve/.rvm/gems/ruby-1.9.1-p378/gems/candy-0.1.0/lib/candy/wrapper.rb:72:in `each'
/Users/steve/.rvm/gems/ruby-1.9.1-p378/gems/candy-0.1.0/lib/candy/wrapper.rb:72:in `wrap_object'
/Users/steve/.rvm/gems/ruby-1.9.1-p378/gems/candy-0.1.0/lib/candy/wrapper.rb:46:in `wrap'
...and so forth.
Because of an embedded object that we couldn't unwrap, I get:
ruby-1.9.1-p378 > c = Register::Person.email('[email protected]')
ArgumentError: wrong number of arguments (0 for 2)
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:132:in `new'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:132:in `unwrap_object'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:92:in `unwrap'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:135:in `block in unwrap_object'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:134:in `each'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:134:in `unwrap_object'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:92:in `unwrap'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:97:in `block in unwrap'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:97:in `map'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:97:in `unwrap'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:114:in `block in unwrap_hash'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:109:in `each'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:109:in `unwrap_hash'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/wrapper.rb:94:in `unwrap'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/piece.rb:82:in `initialize'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/piece.rb:20:in `new'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/piece.rb:20:in `first'
from /Volumes/seley01/Users/steve/.rvm/gems/ruby-1.9.1-p378@sinatra/gems/candy-0.2.6/lib/candy/piece.rb:56:in `method_missing'
from (irb):4
from /Volumes/seley01/Users/steve/.rvm/rubies/ruby-1.9.1-p378/bin/irb:17:in `<main>'
`require': /home/matt/.bundle/ruby/1.8/gems/candy-0.2.6/lib/candy/crunch.rb:219: syntax error, unexpected ':', expecting ']' (SyntaxError)
findandmodify: self.collection.name,
^
/home/matt/.bundle/ruby/1.8/gems/candy-0.2.6/lib/candy/crunch.rb:220: syntax error, unexpected ':', expecting '='
query: query,
^
/home/matt/.bundle/ruby/1.8/gems/candy-0.2.6/lib/candy/crunch.rb:221: syntax error, unexpected ':', expecting '='
update: update,
^
/home/matt/.bundle/ruby/1.8/gems/candy-0.2.6/lib/candy/crunch.rb:222: syntax error, unexpected ':', expecting '='
sort: sort
Breaking on objects with parameters in their initializers is just too brittle. It'd be smarter to try a series of strategies, in order:
Method#parameters
is implemented, as in Ruby 1.9.2.)This is the chain of maximum usefulness within MongoDB queries or data loads. In any of those cases we'll still need to store the strategy used and the class name (except for Marshal).
> t = Thingy.new
> t.whatsit = Widget.new
>t.whatsit.collection # => 'Widget'
This is wrong. The collection should be Thingy.
Spinning up an irb prompt and running:
require 'candy'
Causes the Candy module to create a MongoDb connection to localhost, without actually using any Candy objects. Here's the stack, I'm using a git submodule that is a mirror of this repo:
โ Istoria git:(version_two) โ bundle exec irb
irb(main):001:0> require 'candy'
Mongo::ConnectionFailure: failed to connect to any given host:port
from /home/paul/.bundle/ruby/1.9.1/gems/mongo-1.0/lib/mongo/connection.rb:435:in connect_to_master' from /home/paul/.bundle/ruby/1.9.1/gems/mongo-1.0/lib/mongo/connection.rb:112:in
initialize'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy/crunch.rb:50:in new' from /home/paul/Projects/Istoria/vendor/candy/lib/candy/crunch.rb:50:in
connection'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy/crunch.rb:72:in db' from /home/paul/Projects/Istoria/vendor/candy/lib/candy/crunch.rb:132:in
db'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy/crunch.rb:166:in collection=' from /home/paul/Projects/Istoria/vendor/candy/lib/candy/hash.rb:23:in
class:CandyHash'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy/hash.rb:19:in <module:Candy>' from /home/paul/Projects/Istoria/vendor/candy/lib/candy/hash.rb:3:in
<top (required)>'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy/collection.rb:2:in require' from /home/paul/Projects/Istoria/vendor/candy/lib/candy/collection.rb:2:in
<top (required)>'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy.rb:4:in require' from /home/paul/Projects/Istoria/vendor/candy/lib/candy.rb:4:in
block in <top (required)>'
from /home/paul/Projects/Istoria/vendor/candy/lib/candy.rb:4:in each' from /home/paul/Projects/Istoria/vendor/candy/lib/candy.rb:4:in
<top (required)>'
from (irb):1:in `require'
from (irb):1
class Email
include Candy::Piece
end
class Emails
include Candy::Collection
collects Email
end
Emails.each do |email|
email.provider # => nil
email.refresh
email.provider # => "some value"
end
Imho, it shouldn't be required to manually call email.refresh
The title basically says it all, CandyArray should support #map, unless I am missing a more obvious/efficient way of doing this:
This article on storage optimization talks about using the _id field explicitly to reduce storage space.
I have the following model:
class Game
include Candy::Piece
end
When I try to do:
Game.new(_id: 1, name: 'Pong')
I get the error:
Mongo::OperationFailure: Mod on _id not allowed
Am I doing something wrong, or is this not supported by Candy? Is there a workaround?
The following behavior is very irritating. the key "foo" shouldn't map to a field "'foo'" but rather to "foo", just like :foo does.
Currently you can't just to Person.id(whatever) -- if the 'magic' Person(whatever) method doesn't work, you have to do Person.first(_id: whatever).
This should change.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.