candy 0.2.5 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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.5
1
+ 0.2.6
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{candy}
8
- s.version = "0.2.5"
8
+ s.version = "0.2.6"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Stephen Eley"]
@@ -1,7 +1,17 @@
1
1
  # encoding: utf-8
2
2
 
3
- # Make me one with everything...
4
- Dir[File.join(File.dirname(__FILE__), 'candy', '*.rb')].each {|f| require f}
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.
@@ -10,7 +10,7 @@ module Candy
10
10
  include Crunch
11
11
  include Embeddable
12
12
 
13
- # Included for purposes of 'embeddable' compatbility, but does nothing except pass its
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)
@@ -163,7 +163,7 @@ module Candy
163
163
  when Mongo::Collection
164
164
  @collection = val
165
165
  when String
166
- @collection = db.collection(val)
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(name.sub(/^.*::/,''))
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)
@@ -1,9 +1,6 @@
1
1
  require 'candy/piece'
2
2
 
3
3
  module Candy
4
- # Stubbing to avoid circular dependency problems
5
- module Piece
6
- end
7
4
 
8
5
  # A subclass of Hash that behaves like a Candy::Piece. This class has two major uses:
9
6
  #
@@ -2,7 +2,6 @@ require 'candy/array'
2
2
  require 'candy/crunch'
3
3
  require 'candy/embeddable'
4
4
  require 'candy/factory'
5
- require 'candy/hash'
6
5
 
7
6
  module Candy
8
7
 
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 5
9
- version: 0.2.5
8
+ - 6
9
+ version: 0.2.6
10
10
  platform: ruby
11
11
  authors:
12
12
  - Stephen Eley