Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 76 lines (64 sloc) 2.718 kb
aeff19d @durran Updating doco and gems for 1.9.1
durran authored
1 # Copyright (c) 2009 Durran Jordan
a4d6b69 @durran Moving finders into their own module
durran authored
2 #
aeff19d @durran Updating doco and gems for 1.9.1
durran authored
3 # Permission is hereby granted, free of charge, to any person obtaining
4 # a copy of this software and associated documentation files (the
5 # "Software"), to deal in the Software without restriction, including
6 # without limitation the rights to use, copy, modify, merge, publish,
7 # distribute, sublicense, and/or sell copies of the Software, and to
8 # permit persons to whom the Software is furnished to do so, subject to
9 # the following conditions:
a4d6b69 @durran Moving finders into their own module
durran authored
10 #
aeff19d @durran Updating doco and gems for 1.9.1
durran authored
11 # The above copyright notice and this permission notice shall be
12 # included in all copies or substantial portions of the Software.
a4d6b69 @durran Moving finders into their own module
durran authored
13 #
aeff19d @durran Updating doco and gems for 1.9.1
durran authored
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3d8771a @durran Adding Mogoloid Module and ability to get and set connections
durran authored
21 require "rubygems"
22
7898361 @durran Adding validation support via the Jay Fields' Validatable gem
durran authored
23 gem "activesupport", "2.3.4"
db5f277 @durran Updating gem dependencies
durran authored
24 gem "mongo", "0.15.1"
84beee5 @durran Switching to durran-validatable
durran authored
25 gem "durran-validatable", "1.7.5"
db5f277 @durran Updating gem dependencies
durran authored
26 gem "will_paginate", "2.3.11"
3d8771a @durran Adding Mogoloid Module and ability to get and set connections
durran authored
27
7898361 @durran Adding validation support via the Jay Fields' Validatable gem
durran authored
28 require "validatable"
ac04793 @durran callbacks via activesupport
durran authored
29 require "active_support/callbacks"
30 require "active_support/core_ext"
4c08ed0 @durran Big one: refactoring all associations and removing the old factories
durran authored
31 require "delegate"
f1ef47c @durran Adding will_paginate dependency
durran authored
32 require "will_paginate/collection"
3d8771a @durran Adding Mogoloid Module and ability to get and set connections
durran authored
33 require "mongo"
fe39a32 @durran Moving some requires down the tree to clean up mongoid.rb
durran authored
34 require "mongoid/associations"
37bab68 @durran Initial addition of field class
durran authored
35 require "mongoid/commands"
58a947f @durran Select and Where in DSL
durran authored
36 require "mongoid/criteria"
5c937c1 @durran Associations can now be set directly
durran authored
37 require "mongoid/extensions"
37bab68 @durran Initial addition of field class
durran authored
38 require "mongoid/field"
0d36672 @durran Renaming to something fake and less offensive
durran authored
39 require "mongoid/document"
3d8771a @durran Adding Mogoloid Module and ability to get and set connections
durran authored
40
0d36672 @durran Renaming to something fake and less offensive
durran authored
41 module Mongoid
6e8b72a @durran Iniitial document modeling and specs
durran authored
42
3ecf8d6 @durran Adding commands module into document
durran authored
43 # Raised when the database connection has not been set up.
44 class NoConnectionError < RuntimeError; end
6e8b72a @durran Iniitial document modeling and specs
durran authored
45
3ecf8d6 @durran Adding commands module into document
durran authored
46 # Raised when :document_class is not provided in the attributes
e500a91 @durran Moving exceptions to mongoloid root
durran authored
47 # hash when creating a new Document
3ecf8d6 @durran Adding commands module into document
durran authored
48 class ClassNotProvidedError < RuntimeError; end
e500a91 @durran Moving exceptions to mongoloid root
durran authored
49
3ecf8d6 @durran Adding commands module into document
durran authored
50 # Raised when an association is defined on the class, but the
e500a91 @durran Moving exceptions to mongoloid root
durran authored
51 # attribute in the hash is not an Array or Hash.
3ecf8d6 @durran Adding commands module into document
durran authored
52 class TypeMismatchError < RuntimeError; end
e500a91 @durran Moving exceptions to mongoloid root
durran authored
53
3ecf8d6 @durran Adding commands module into document
durran authored
54 # Raised when an association is defined that is not valid. Must
e500a91 @durran Moving exceptions to mongoloid root
durran authored
55 # be belongs_to, has_many, has_one
3ecf8d6 @durran Adding commands module into document
durran authored
56 class InvalidAssociationError < RuntimeError; end
57
58 # Raised when a persisence method ending in ! fails validation.
59 class ValidationsError < RuntimeError; end
e500a91 @durran Moving exceptions to mongoloid root
durran authored
60
b9948c4 @durran Adding simple find that takes a selector
durran authored
61 # Connect to the database name supplied. This should be run
62 # for initial setup, potentially in a rails initializer.
6e8b72a @durran Iniitial document modeling and specs
durran authored
63 def self.connect_to(name)
eb4b182 @durran Removing XGen namespace
durran authored
64 @@connection ||= Mongo::Connection.new
6e8b72a @durran Iniitial document modeling and specs
durran authored
65 @@database ||= @@connection.db(name)
3d8771a @durran Adding Mogoloid Module and ability to get and set connections
durran authored
66 end
6e8b72a @durran Iniitial document modeling and specs
durran authored
67
0d36672 @durran Renaming to something fake and less offensive
durran authored
68 # Get the MongoDB database. If initialization via Mongoid.connect_to()
b9948c4 @durran Adding simple find that takes a selector
durran authored
69 # has not happened, an exception will occur.
6e8b72a @durran Iniitial document modeling and specs
durran authored
70 def self.database
71 raise NoConnectionError unless @@database
72 @@database
73 end
74
75 end
Something went wrong with that request. Please try again.