GithubHelp home page GithubHelp logo

candy's People

Contributors

sfeley avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

candy's Issues

Candy shouldn't try to connect to localhost just by requiring it

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:ininitialize'
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:inconnection'
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:indb'
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:inclass: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:inblock 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

Wrapping objects sometimes infinite loops

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.

Querying on ID is too hard

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.

Unwrapping objects with parameterized initializers should fail with warnings, not exceptions

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>'

Query methods overridden by common class method names

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>'

trouble getting candy to load

`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

Need more robust serialization of non-Candy objects

Breaking on objects with parameters in their initializers is just too brittle. It'd be smarter to try a series of strategies, in order:

  1. to_mongo if the object responds to from_mongo
  2. to_json if the object responds to from_json
  3. The current Candy::Wrapper class-and-ivars serialization if the object initializer's arity is 0 (Note: make it even smarter if Method#parameters is implemented, as in Ruby 1.9.2.)
  4. Marshal.dump if the object responds to Marshal.load
  5. Throw an exception if none of the above works.

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).

Cannot set the _id field explicitly

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?

Objects to be embedded getting saved to the database

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.