Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Default collection names no longer include module namespace paths

  • Loading branch information...
commit fadc1c37764f5c34fb44afe3f67bb553fd9fc175 1 parent 0eb97dc
Stephen Eley authored
3  .gitignore
View
@@ -5,6 +5,9 @@
*.tmproj
tmtags
+## RVM
+.rvmrc
+
## EMACS
*~
\#*
17 HISTORY.markdown
View
@@ -3,11 +3,20 @@ Candy History
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`.
+v0.2.5 - 2010-05-02 (the "John::Jacob::Jingleheimer::Schmidt" release)
+----------------------------------------------------------------------
+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.
+
+* Default collection names no longer include module namespace paths
+
+
v0.2.4 - 2010-04-21 (the "No shortcuts!" release)
--------------------------------------------------
-While building validations and custom behavior on a new app, I realized that any method overrides in my classes
-were being bypassed if I passed the values in a hash to .new() -- it was just setting everything straight in Mongo.
-Inconsistent behavior is uncool. So now every hash key calls the relevant assignment method in the class.
+-------------------------------------------------
+While building validations and custom behavior on a new app, I realized that
+any method overrides in my classes were being bypassed if I passed the values
+in a hash to .new() -- it was just setting everything straight in Mongo.
+Inconsistent behavior is uncool. So now every hash key calls the relevant
+assignment method in the class.
* Values passed in hash to new objects call the relevant assignment methods
* Fixed typo in README (thanks, kfl62)
9 lib/candy/collection.rb
View
@@ -16,16 +16,13 @@ module ClassMethods
attr_reader :_candy_piece
- # Sets the collection that all queries run against, qualified by
- # the namespace of the current class. (I.e., if this class is
- # BigModule::LittleModule::People, `collects :person` will look for
- # a collection named "BigModule::LittleModule::Person".) You can also
+ # Sets the collection that all queries run against. You can also
# specify a class that includes Candy::Piece that will be instantiated
# for all found records. Otherwise the collection name is used as a
# default, and CandyHash is a fallback.
def collects(collection, piece = nil)
- collectible = namespace + camelcase(collection)
- piecemeal = (piece ? namespace + camelcase(piece) : collectible)
+ collectible = camelcase(collection)
+ piecemeal = namespace + (piece ? camelcase(piece) : collectible)
self.collection = collectible
@_candy_piece = Kernel.qualified_const_get(piecemeal) || CandyHash
end
3  lib/candy/crunch.rb
View
@@ -172,8 +172,9 @@ def collection=(val)
end
# Returns the collection you gave, or creates a default collection named for the current class.
+ # (By which we mean _just_ the class name, not the full module namespace.)
def collection
- @collection ||= db.collection(name)
+ @collection ||= db.collection(name.sub(/^.*::/,''))
end
# Creates an index on the specified property, with an optional direction specified as either :asc or :desc.
4 spec/candy/crunch_spec.rb
View
@@ -95,7 +95,7 @@ class PeanutBrittle
it "clears the collection when you set it" do
PeanutBrittle.db = 'candy_test'
- PeanutBrittle.collection.name.should == PeanutBrittle.name
+ PeanutBrittle.collection.name.should == 'PeanutBrittle'
PeanutBrittle.db = nil
PeanutBrittle.instance_variable_get(:@collection).should be_nil
end
@@ -151,7 +151,7 @@ class PeanutBrittle
end
it "defaults to the class name" do
- PeanutBrittle.collection.name.should == PeanutBrittle.name
+ PeanutBrittle.collection.name.should == 'PeanutBrittle'
end
it "throws an exception if you give it a type it can't recognize" do
Please sign in to comment.
Something went wrong with that request. Please try again.