mongo_odm 0.2.10 → 0.2.11

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.
data/README.rdoc CHANGED
@@ -89,7 +89,7 @@ You can also define your own class methods that returns criteria objects, and co
89
89
 
90
90
  Take a look at the Mongo Ruby driver documentation for the 'find' method to see the available options:
91
91
 
92
- http://api.mongodb.org/ruby/1.0.8/Mongo/Collection.html#find-instance_method
92
+ http://api.mongodb.org/ruby/1.2.4/Mongo/Collection.html#find-instance_method
93
93
 
94
94
  = Collections
95
95
 
@@ -434,7 +434,7 @@ Use cursor methods directly on the class:
434
434
 
435
435
  For now, take a look at the Mongo Ruby driver syntax:
436
436
 
437
- http://api.mongodb.org/ruby/1.0.8/index.html
437
+ http://api.mongodb.org/ruby/1.2.4/index.html
438
438
 
439
439
  = Credits
440
440
 
@@ -45,6 +45,11 @@ class BSON::DBRef
45
45
  def inspect
46
46
  "BSON::DBRef(namespace:\"#{namespace}\", id: \"#{object_id}\")"
47
47
  end
48
+
49
+ def eql?(other)
50
+ to_hash == other.to_hash
51
+ end
52
+ alias :== :eql?
48
53
  end
49
54
 
50
55
  # @private
@@ -205,7 +210,7 @@ end
205
210
 
206
211
  # Stand-in for true/false property types.
207
212
  # @private
208
- module Boolean
213
+ class Boolean
209
214
  def self.type_cast(value)
210
215
  case value
211
216
  when NilClass
@@ -44,7 +44,7 @@ module MongoODM
44
44
  if respond_to?(:"#{name}=")
45
45
  send(:"#{name}=", value)
46
46
  else
47
- auto_generate_attributes ? write_attribute(name, value) : raise(MongoODM::Errors::UnknownFieldError, "unknown field: #{name}")
47
+ auto_generate_attributes ? write_attribute(name, value) : raise(MongoODM::Errors::UnknownFieldError, name, self.class)
48
48
  end
49
49
  end
50
50
  end
@@ -14,8 +14,9 @@ module MongoODM
14
14
 
15
15
  define_model_callbacks :initialize, :only => :after
16
16
  define_model_callbacks :save, :destroy
17
+ define_model_callbacks :validate, :only => :before
17
18
  end
18
-
19
+
19
20
  module InstanceMethods
20
21
  def initialize_with_callbacks(*args)
21
22
  initialize_without_callbacks(*args)
@@ -30,7 +30,8 @@ module MongoODM
30
30
 
31
31
  # @return [Object] The default value for this field if defined, or nil.
32
32
  def default
33
- if default = options[:default]
33
+ if options.has_key?(:default)
34
+ default = options[:default]
34
35
  type_cast(default.respond_to?(:call) ? default.call : default)
35
36
  end
36
37
  end
@@ -13,6 +13,18 @@ module MongoODM
13
13
  super "can't localize field #{field_name}; it has to be declared as a Hash, was #{klass}"
14
14
  end
15
15
  end
16
+
17
+ class UnknownFieldError < StandardError
18
+ def initialize(field_name, klass)
19
+ super "unknown field #{field_name} on class #{klass.name}"
20
+ end
21
+ end
22
+
23
+ class DocumentNotFound < StandardError
24
+ def initialize(ids, klass)
25
+ super "can't find document for class #{klass} with id(s) #{ids}"
26
+ end
27
+ end
16
28
  end
17
29
 
18
30
  end
@@ -2,6 +2,6 @@
2
2
  module MongoODM
3
3
  VERSION_MAJOR = "0"
4
4
  VERSION_MINOR = "2"
5
- VERSION_BUILD = "10"
5
+ VERSION_BUILD = "11"
6
6
  VERSION = "#{VERSION_MAJOR}.#{VERSION_MINOR}.#{VERSION_BUILD}"
7
7
  end
data/lib/mongo_odm.rb CHANGED
@@ -2,6 +2,7 @@
2
2
  require 'rubygems'
3
3
  require 'mongo'
4
4
  require 'active_support'
5
+ require 'active_support/core_ext/hash'
5
6
  require 'active_model'
6
7
 
7
8
  # Contains the classes and modules related to the ODM built on top of the basic Mongo client.
@@ -46,7 +47,7 @@ module MongoODM
46
47
  end
47
48
  value.class.type_cast(value.to_mongo)
48
49
  end
49
-
50
+
50
51
  def self.dereference(value)
51
52
  value.respond_to?(:dereference) ? value.dereference : value
52
53
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: mongo_odm
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.10
5
+ version: 0.2.11
6
6
  platform: ruby
7
7
  authors:
8
8
  - Carlos Paramio