candy 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY.markdown +9 -0
- data/VERSION +1 -1
- data/candy.gemspec +1 -1
- data/lib/candy.rb +12 -2
- data/lib/candy/array.rb +1 -1
- data/lib/candy/crunch.rb +11 -2
- data/lib/candy/hash.rb +0 -3
- data/lib/candy/piece.rb +0 -1
- metadata +2 -2
data/HISTORY.markdown
CHANGED
@@ -3,6 +3,15 @@ Candy History
|
|
3
3
|
|
4
4
|
This document aims to provide only an overview. Further, we've only really been tracking things since **v0.2**. For obsessive detail, just check out the `git log`.
|
5
5
|
|
6
|
+
v0.2.6 - 2010-05-03 (the "Spanish Fly" release)
|
7
|
+
-----------------------------------------------
|
8
|
+
Thanks to [xpaulbettsx](http://github.com/xpaulbettsx) for pointing out in issue \#4 that Candy was attempting to connect to localhost prematurely.
|
9
|
+
A stray setting of the collection name in CandyHash was the culprit, causing a cascade of lookups. Refactored to maintain lazy evaluation of the whole MongoDB object chain, and while I was at it, moved most of the interesting objects into `autoload` conditions in the main Candy file instead of `require`.
|
10
|
+
|
11
|
+
* Reorganized for autoloading
|
12
|
+
* Fixed issue #4 - tries to connect to host immediately on require
|
13
|
+
|
14
|
+
|
6
15
|
v0.2.5 - 2010-05-02 (the "John::Jacob::Jingleheimer::Schmidt" release)
|
7
16
|
----------------------------------------------------------------------
|
8
17
|
As I was building an app based on several Sinatra building blocks, I realized that Candy was creating collection names like **Login::Person** and **Profile::Person** with complete module namespaces. I wanted both of those **Person** classes to be different views on the same data, and having to override the collection name each time was becoming a pain. I'm not sure that fully namespacing the collection names inside Mongo has much value, and we weren't really documenting that it was happening, so I've simplified things.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.6
|
data/candy.gemspec
CHANGED
data/lib/candy.rb
CHANGED
@@ -1,7 +1,17 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
require 'candy/crunch'
|
4
|
+
require 'candy/exceptions'
|
5
|
+
|
6
|
+
module Candy
|
7
|
+
# Let's be minimalist here. Some implementations may not need Collections, or Arrays, etc.
|
8
|
+
# Anything not in the autoload list below is unlikely to be accessed directly by an end user.
|
9
|
+
autoload :CandyHash, 'candy/hash'
|
10
|
+
autoload :CandyArray, 'candy/array'
|
11
|
+
autoload :Wrapper, 'candy/wrapper'
|
12
|
+
autoload :Piece, 'candy/piece'
|
13
|
+
autoload :Collection, 'candy/collection'
|
14
|
+
end
|
5
15
|
|
6
16
|
# Special keys for Candy metadata in the Mongo store. We try to keep these to a minimum,
|
7
17
|
# and we're using moderately obscure Unicode symbols to reduce the odds of collisions.
|
data/lib/candy/array.rb
CHANGED
@@ -10,7 +10,7 @@ module Candy
|
|
10
10
|
include Crunch
|
11
11
|
include Embeddable
|
12
12
|
|
13
|
-
# Included for purposes of 'embeddable'
|
13
|
+
# Included for purposes of 'embeddable' compatibility, but does nothing except pass its
|
14
14
|
# parameters to the new object. Since you can't save an array on its own anyway, there's
|
15
15
|
# no need to flag it as "don't save."
|
16
16
|
def self.embed(*args, &block)
|
data/lib/candy/crunch.rb
CHANGED
@@ -163,7 +163,7 @@ module Candy
|
|
163
163
|
when Mongo::Collection
|
164
164
|
@collection = val
|
165
165
|
when String
|
166
|
-
@
|
166
|
+
@collection_name = val # Don't collapse the probability wave until called upon
|
167
167
|
when nil
|
168
168
|
@collection = nil
|
169
169
|
else
|
@@ -174,7 +174,7 @@ module Candy
|
|
174
174
|
# Returns the collection you gave, or creates a default collection named for the current class.
|
175
175
|
# (By which we mean _just_ the class name, not the full module namespace.)
|
176
176
|
def collection
|
177
|
-
@collection ||= db.collection(
|
177
|
+
@collection ||= db.collection(collection_name)
|
178
178
|
end
|
179
179
|
|
180
180
|
# Creates an index on the specified property, with an optional direction specified as either :asc or :desc.
|
@@ -191,6 +191,15 @@ module Candy
|
|
191
191
|
end
|
192
192
|
|
193
193
|
private
|
194
|
+
# If we were passed a string on #collection= then we want to pass it to the DB when the collection is referenced,
|
195
|
+
# not right away. So store it and pass it back on the initial call to #collection. If nothing, pass the
|
196
|
+
# class name instead.
|
197
|
+
def collection_name
|
198
|
+
collection_name = @collection_name || name.sub(/^.*::/,'')
|
199
|
+
@collection_name = nil # Forget this name to avoid confusion on subsequent calls
|
200
|
+
collection_name
|
201
|
+
end
|
202
|
+
|
194
203
|
# If we don't have a username AND password, returns the DB given. If we do, returns the DB if-and-only-if
|
195
204
|
# we can authenticate on that DB.
|
196
205
|
def maybe_authenticate(db)
|
data/lib/candy/hash.rb
CHANGED
data/lib/candy/piece.rb
CHANGED