mongo_odm 0.2.17 → 0.2.18
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 +11 -0
- data/lib/mongo_odm/document/attribute_methods.rb +1 -1
- data/lib/mongo_odm/version.rb +1 -1
- metadata +1 -1
data/README.rdoc
CHANGED
@@ -76,6 +76,8 @@ And because any query method returns a MongoODM::Criteria object, you can concat
|
|
76
76
|
You can also define your own class methods that returns criteria objects, and concatenate them to obtain a single criteria with all the conditions merged in the calls order:
|
77
77
|
|
78
78
|
class Shape
|
79
|
+
include MongoODM::Document
|
80
|
+
|
79
81
|
def self.with_radius(n)
|
80
82
|
find(:radius => n)
|
81
83
|
end
|
@@ -87,6 +89,15 @@ You can also define your own class methods that returns criteria objects, and co
|
|
87
89
|
|
88
90
|
Shape.with_radius(1).ordered_by_color # Returns the same criteria than the previous example
|
89
91
|
|
92
|
+
Default values for fields can be either a fixed value, or a block, in which case the block will be called each time an object is instantiated. Example:
|
93
|
+
|
94
|
+
class Timestamp
|
95
|
+
include MongoODM::Document
|
96
|
+
|
97
|
+
field :value, Time, :default => lambda { Time.now }
|
98
|
+
field :set, Set, :default => lambda { Set.new }
|
99
|
+
end
|
100
|
+
|
90
101
|
Take a look at the Mongo Ruby driver documentation for the 'find' method to see the available options:
|
91
102
|
|
92
103
|
http://api.mongodb.org/ruby/1.2.4/Mongo/Collection.html#find-instance_method
|
@@ -92,7 +92,7 @@ module MongoODM
|
|
92
92
|
|
93
93
|
module ClassMethods
|
94
94
|
def default_attributes
|
95
|
-
HashWithIndifferentAccess[fields.values.map{|field| [field.name, field.default]}]
|
95
|
+
HashWithIndifferentAccess[fields.values.map{|field| [field.name, field.default.respond_to?(:call) ? field.default.call : field.default]}]
|
96
96
|
end
|
97
97
|
|
98
98
|
def define_attribute_methods_for_fields
|
data/lib/mongo_odm/version.rb
CHANGED