mongoid 2.0.0.beta.20 → 2.0.0.rc.1
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 +8 -0
- data/Rakefile +51 -0
- data/lib/config/locales/nl.yml +39 -0
- data/lib/config/locales/ro.yml +1 -1
- data/lib/mongoid.rb +17 -17
- data/lib/mongoid/atomicity.rb +54 -22
- data/lib/mongoid/attributes.rb +145 -125
- data/lib/mongoid/callbacks.rb +7 -2
- data/lib/mongoid/collection.rb +49 -32
- data/lib/mongoid/collections.rb +0 -1
- data/lib/mongoid/components.rb +34 -29
- data/lib/mongoid/config.rb +207 -193
- data/lib/mongoid/config/database.rb +167 -0
- data/lib/mongoid/contexts.rb +2 -5
- data/lib/mongoid/contexts/enumerable.rb +30 -4
- data/lib/mongoid/contexts/ids.rb +2 -2
- data/lib/mongoid/contexts/mongo.rb +30 -5
- data/lib/mongoid/copyable.rb +44 -0
- data/lib/mongoid/criteria.rb +110 -56
- data/lib/mongoid/criterion/creational.rb +34 -0
- data/lib/mongoid/criterion/destructive.rb +37 -0
- data/lib/mongoid/criterion/exclusion.rb +3 -1
- data/lib/mongoid/criterion/inclusion.rb +59 -64
- data/lib/mongoid/criterion/inspection.rb +22 -0
- data/lib/mongoid/criterion/optional.rb +42 -54
- data/lib/mongoid/criterion/selector.rb +9 -0
- data/lib/mongoid/default_scope.rb +28 -0
- data/lib/mongoid/deprecation.rb +5 -5
- data/lib/mongoid/dirty.rb +4 -5
- data/lib/mongoid/document.rb +161 -114
- data/lib/mongoid/extensions.rb +7 -11
- data/lib/mongoid/extensions/array/parentization.rb +2 -2
- data/lib/mongoid/extensions/date/conversions.rb +1 -1
- data/lib/mongoid/extensions/hash/conversions.rb +0 -23
- data/lib/mongoid/extensions/nil/collectionization.rb +12 -0
- data/lib/mongoid/extensions/object/reflections.rb +17 -0
- data/lib/mongoid/extensions/object/yoda.rb +27 -0
- data/lib/mongoid/extensions/string/conversions.rb +23 -4
- data/lib/mongoid/extensions/time_conversions.rb +4 -4
- data/lib/mongoid/field.rb +30 -19
- data/lib/mongoid/fields.rb +15 -5
- data/lib/mongoid/finders.rb +19 -11
- data/lib/mongoid/hierarchy.rb +34 -28
- data/lib/mongoid/identity.rb +62 -20
- data/lib/mongoid/inspection.rb +58 -0
- data/lib/mongoid/matchers.rb +20 -0
- data/lib/mongoid/multi_database.rb +11 -0
- data/lib/mongoid/nested_attributes.rb +41 -0
- data/lib/mongoid/paranoia.rb +3 -4
- data/lib/mongoid/paths.rb +1 -1
- data/lib/mongoid/persistence.rb +89 -90
- data/lib/mongoid/persistence/command.rb +20 -4
- data/lib/mongoid/persistence/insert.rb +13 -11
- data/lib/mongoid/persistence/insert_embedded.rb +8 -6
- data/lib/mongoid/persistence/remove.rb +6 -4
- data/lib/mongoid/persistence/remove_all.rb +6 -4
- data/lib/mongoid/persistence/remove_embedded.rb +8 -6
- data/lib/mongoid/persistence/update.rb +12 -10
- data/lib/mongoid/railtie.rb +2 -2
- data/lib/mongoid/railties/database.rake +10 -9
- data/lib/mongoid/relations.rb +104 -0
- data/lib/mongoid/relations/accessors.rb +154 -0
- data/lib/mongoid/relations/auto_save.rb +34 -0
- data/lib/mongoid/relations/binding.rb +24 -0
- data/lib/mongoid/relations/bindings.rb +9 -0
- data/lib/mongoid/relations/bindings/embedded/in.rb +77 -0
- data/lib/mongoid/relations/bindings/embedded/many.rb +93 -0
- data/lib/mongoid/relations/bindings/embedded/one.rb +65 -0
- data/lib/mongoid/relations/bindings/referenced/in.rb +78 -0
- data/lib/mongoid/relations/bindings/referenced/many.rb +93 -0
- data/lib/mongoid/relations/bindings/referenced/many_to_many.rb +94 -0
- data/lib/mongoid/relations/bindings/referenced/one.rb +63 -0
- data/lib/mongoid/relations/builder.rb +41 -0
- data/lib/mongoid/relations/builders.rb +79 -0
- data/lib/mongoid/relations/builders/embedded/in.rb +25 -0
- data/lib/mongoid/relations/builders/embedded/many.rb +32 -0
- data/lib/mongoid/relations/builders/embedded/one.rb +26 -0
- data/lib/mongoid/relations/builders/nested_attributes/many.rb +116 -0
- data/lib/mongoid/relations/builders/nested_attributes/one.rb +135 -0
- data/lib/mongoid/relations/builders/referenced/in.rb +32 -0
- data/lib/mongoid/relations/builders/referenced/many.rb +26 -0
- data/lib/mongoid/relations/builders/referenced/many_to_many.rb +29 -0
- data/lib/mongoid/relations/builders/referenced/one.rb +30 -0
- data/lib/mongoid/relations/cascading.rb +55 -0
- data/lib/mongoid/relations/cascading/delete.rb +19 -0
- data/lib/mongoid/relations/cascading/destroy.rb +19 -0
- data/lib/mongoid/relations/cascading/nullify.rb +18 -0
- data/lib/mongoid/relations/cascading/strategy.rb +26 -0
- data/lib/mongoid/relations/cyclic.rb +97 -0
- data/lib/mongoid/relations/embedded/in.rb +172 -0
- data/lib/mongoid/relations/embedded/many.rb +450 -0
- data/lib/mongoid/relations/embedded/one.rb +169 -0
- data/lib/mongoid/relations/macros.rb +302 -0
- data/lib/mongoid/relations/many.rb +185 -0
- data/lib/mongoid/relations/metadata.rb +529 -0
- data/lib/mongoid/relations/nested_builder.rb +52 -0
- data/lib/mongoid/relations/one.rb +29 -0
- data/lib/mongoid/relations/polymorphic.rb +54 -0
- data/lib/mongoid/relations/proxy.rb +122 -0
- data/lib/mongoid/relations/referenced/in.rb +214 -0
- data/lib/mongoid/relations/referenced/many.rb +358 -0
- data/lib/mongoid/relations/referenced/many_to_many.rb +379 -0
- data/lib/mongoid/relations/referenced/one.rb +204 -0
- data/lib/mongoid/relations/reflections.rb +45 -0
- data/lib/mongoid/safe.rb +11 -1
- data/lib/mongoid/safety.rb +122 -97
- data/lib/mongoid/scope.rb +14 -9
- data/lib/mongoid/state.rb +37 -3
- data/lib/mongoid/timestamps.rb +11 -0
- data/lib/mongoid/validations.rb +42 -3
- data/lib/mongoid/validations/associated.rb +8 -5
- data/lib/mongoid/validations/uniqueness.rb +23 -2
- data/lib/mongoid/version.rb +1 -1
- data/lib/mongoid/versioning.rb +25 -16
- data/lib/rails/generators/mongoid/model/templates/model.rb +3 -1
- metadata +95 -80
- data/lib/mongoid/associations.rb +0 -364
- data/lib/mongoid/associations/embedded_in.rb +0 -74
- data/lib/mongoid/associations/embeds_many.rb +0 -299
- data/lib/mongoid/associations/embeds_one.rb +0 -111
- data/lib/mongoid/associations/foreign_key.rb +0 -35
- data/lib/mongoid/associations/meta_data.rb +0 -38
- data/lib/mongoid/associations/options.rb +0 -78
- data/lib/mongoid/associations/proxy.rb +0 -60
- data/lib/mongoid/associations/referenced_in.rb +0 -70
- data/lib/mongoid/associations/references_many.rb +0 -254
- data/lib/mongoid/associations/references_many_as_array.rb +0 -128
- data/lib/mongoid/associations/references_one.rb +0 -104
- data/lib/mongoid/extensions/array/accessors.rb +0 -17
- data/lib/mongoid/extensions/array/assimilation.rb +0 -26
- data/lib/mongoid/extensions/hash/accessors.rb +0 -42
- data/lib/mongoid/extensions/hash/assimilation.rb +0 -40
- data/lib/mongoid/extensions/nil/assimilation.rb +0 -17
- data/lib/mongoid/memoization.rb +0 -33
data/lib/mongoid/scope.rb
CHANGED
@@ -1,26 +1,31 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid #:nodoc:
|
3
|
-
|
4
|
-
|
3
|
+
# This module handles behaviour for defining scopes on classes.
|
4
|
+
class Scope
|
5
5
|
attr_reader :conditions, :extensions
|
6
6
|
|
7
7
|
# Create the new +Scope+. If a block is passed in, this Scope will store
|
8
8
|
# the block for future calls to #extend.
|
9
9
|
#
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# conditions: A +Hash+ of conditions.
|
13
|
-
# block: A +block+ of extension methods (optional)
|
10
|
+
# @example Create a new scope.
|
11
|
+
# Scope.new(:title => "Sir")
|
14
12
|
#
|
13
|
+
# @param [ Hash ] conditions The scoping limitations.
|
15
14
|
def initialize(conditions = {}, &block)
|
16
15
|
@conditions = conditions
|
17
16
|
@extensions = Module.new(&block) if block_given?
|
18
17
|
end
|
19
18
|
|
19
|
+
# Extend a supplied criteria.
|
20
|
+
#
|
21
|
+
# @example Extend the criteria.
|
22
|
+
# scope.extend(criteria)
|
23
|
+
#
|
24
|
+
# @param [ Criteria } criteria A mongoid criteria to extend.
|
25
|
+
#
|
26
|
+
# @return [ Criteria ] The new criteria object.
|
20
27
|
def extend(criteria)
|
21
|
-
|
28
|
+
extensions ? criteria.extend(extensions) : criteria
|
22
29
|
end
|
23
|
-
|
24
30
|
end
|
25
31
|
end
|
26
|
-
|
data/lib/mongoid/state.rb
CHANGED
@@ -1,30 +1,64 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid #:nodoc:
|
3
|
-
|
3
|
+
|
4
|
+
# This module contains the behaviour for getting the various states a
|
5
|
+
# document can transition through.
|
6
|
+
module State
|
7
|
+
|
4
8
|
# Returns true if the +Document+ has not been persisted to the database,
|
5
9
|
# false if it has. This is determined by the variable @new_record
|
6
10
|
# and NOT if the object has an id.
|
11
|
+
#
|
12
|
+
# @example Is the document new?
|
13
|
+
# person.new_record?
|
14
|
+
#
|
15
|
+
# @return [ true, false ] True if new, false if not.
|
7
16
|
def new_record?
|
8
17
|
@new_record == true
|
9
18
|
end
|
19
|
+
alias :new? :new_record?
|
10
20
|
|
11
21
|
# Sets the new_record boolean - used after document is saved.
|
22
|
+
#
|
23
|
+
# @example Set whether the document is new.
|
24
|
+
# person.new_record = true
|
25
|
+
#
|
26
|
+
# @param [ true, false ] saved The value to set for new_record.
|
27
|
+
#
|
28
|
+
# @return [ true, false ] The new_record value.
|
12
29
|
def new_record=(saved)
|
13
30
|
@new_record = saved
|
14
31
|
end
|
15
32
|
|
16
33
|
# Checks if the document has been saved to the database.
|
34
|
+
#
|
35
|
+
# @example Is the document persisted?
|
36
|
+
# person.persisted?
|
37
|
+
#
|
38
|
+
# @return [ true, false ] True if persisted, false if not.
|
17
39
|
def persisted?
|
18
40
|
!new_record?
|
19
41
|
end
|
20
42
|
|
21
|
-
# Returns true if the +Document+ has been succesfully destroyed, and false
|
22
|
-
# This is determined by the variable @destroyed and NOT
|
43
|
+
# Returns true if the +Document+ has been succesfully destroyed, and false
|
44
|
+
# if it hasn't. This is determined by the variable @destroyed and NOT
|
45
|
+
# by checking the database.
|
46
|
+
#
|
47
|
+
# @example Is the document destroyed?
|
48
|
+
# person.destroyed?
|
49
|
+
#
|
50
|
+
# @return [ true, false ] True if destroyed, false if not.
|
23
51
|
def destroyed?
|
24
52
|
@destroyed == true
|
25
53
|
end
|
54
|
+
alias :deleted? :destroyed?
|
26
55
|
|
27
56
|
# Sets the destroyed boolean - used after document is destroyed.
|
57
|
+
#
|
58
|
+
# @example Set the destroyed flag.
|
59
|
+
# person.destroyed = true
|
60
|
+
#
|
61
|
+
# @return [ true, false ] The value set for destroyed.
|
28
62
|
def destroyed=(destroyed)
|
29
63
|
@destroyed = destroyed && true
|
30
64
|
end
|
data/lib/mongoid/timestamps.rb
CHANGED
@@ -1,10 +1,15 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid #:nodoc:
|
3
|
+
|
4
|
+
# This module handles the behaviour for setting up document created at and
|
5
|
+
# updated at timestamps.
|
3
6
|
module Timestamps
|
4
7
|
extend ActiveSupport::Concern
|
8
|
+
|
5
9
|
included do
|
6
10
|
field :created_at, :type => Time
|
7
11
|
field :updated_at, :type => Time
|
12
|
+
|
8
13
|
set_callback :create, :before, :set_created_at
|
9
14
|
set_callback :save, :before, :set_updated_at
|
10
15
|
|
@@ -14,12 +19,18 @@ module Mongoid #:nodoc:
|
|
14
19
|
|
15
20
|
# Update the created_at field on the Document to the current time. This is
|
16
21
|
# only called on create.
|
22
|
+
#
|
23
|
+
# @example Set the created at time.
|
24
|
+
# person.set_created_at
|
17
25
|
def set_created_at
|
18
26
|
self.created_at = Time.now.utc if !created_at
|
19
27
|
end
|
20
28
|
|
21
29
|
# Update the updated_at field on the Document to the current time.
|
22
30
|
# This is only called on create and on save.
|
31
|
+
#
|
32
|
+
# @example Set the updated at time.
|
33
|
+
# person.set_updated_at
|
23
34
|
def set_updated_at
|
24
35
|
self.updated_at = Time.now.utc
|
25
36
|
end
|
data/lib/mongoid/validations.rb
CHANGED
@@ -3,19 +3,39 @@ require "mongoid/validations/associated"
|
|
3
3
|
require "mongoid/validations/uniqueness"
|
4
4
|
|
5
5
|
module Mongoid #:nodoc:
|
6
|
+
|
6
7
|
# This module provides additional validations that ActiveModel does not
|
7
|
-
# provide: validates_associated and validates_uniqueness_of
|
8
|
+
# provide: validates_associated and validates_uniqueness_of.
|
8
9
|
module Validations
|
9
10
|
extend ActiveSupport::Concern
|
11
|
+
|
10
12
|
included do
|
11
13
|
include ActiveModel::Validations
|
14
|
+
|
15
|
+
# Overrides the default ActiveModel behaviour since we need to handle
|
16
|
+
# validations of relations slightly different than just calling the
|
17
|
+
# getter.
|
18
|
+
#
|
19
|
+
# @todo Durran: Why does moving the ActiveModel::Validations include
|
20
|
+
# statement outside of the block bomb the test suite. This feels dirty.
|
21
|
+
#
|
22
|
+
# @example Read the value.
|
23
|
+
# person.read_attribute_for_validation(:addresses)
|
24
|
+
#
|
25
|
+
# @param [ Symbol ] attr The name of the field or relation.
|
26
|
+
#
|
27
|
+
# @return [ Object ] The value of the field or the relation.
|
28
|
+
def read_attribute_for_validation(attr)
|
29
|
+
relations[attr.to_s] ? send(attr, false, :continue => false) : send(attr)
|
30
|
+
end
|
12
31
|
end
|
13
32
|
|
14
33
|
module ClassMethods #:nodoc:
|
34
|
+
|
15
35
|
# Validates whether or not an association is valid or not. Will correctly
|
16
36
|
# handle has one and has many associations.
|
17
37
|
#
|
18
|
-
#
|
38
|
+
# @example
|
19
39
|
#
|
20
40
|
# class Person
|
21
41
|
# include Mongoid::Document
|
@@ -24,6 +44,8 @@ module Mongoid #:nodoc:
|
|
24
44
|
#
|
25
45
|
# validates_associated :name, :addresses
|
26
46
|
# end
|
47
|
+
#
|
48
|
+
# @param [ Array ] *args The arguments to pass to the validator.
|
27
49
|
def validates_associated(*args)
|
28
50
|
validates_with(AssociatedValidator, _merge_attributes(args))
|
29
51
|
end
|
@@ -31,7 +53,7 @@ module Mongoid #:nodoc:
|
|
31
53
|
# Validates whether or not a field is unique against the documents in the
|
32
54
|
# database.
|
33
55
|
#
|
34
|
-
#
|
56
|
+
# @example
|
35
57
|
#
|
36
58
|
# class Person
|
37
59
|
# include Mongoid::Document
|
@@ -39,9 +61,26 @@ module Mongoid #:nodoc:
|
|
39
61
|
#
|
40
62
|
# validates_uniqueness_of :title
|
41
63
|
# end
|
64
|
+
#
|
65
|
+
# @param [ Array ] *args The arguments to pass to the validator.
|
42
66
|
def validates_uniqueness_of(*args)
|
43
67
|
validates_with(UniquenessValidator, _merge_attributes(args))
|
44
68
|
end
|
69
|
+
|
70
|
+
protected
|
71
|
+
|
72
|
+
# Adds an associated validator for the relation if the validate option
|
73
|
+
# was not provided or set to true.
|
74
|
+
#
|
75
|
+
# @example Set up validation.
|
76
|
+
# Person.validate_relation(metadata)
|
77
|
+
#
|
78
|
+
# @param [ Metadata ] metadata The relation metadata.
|
79
|
+
#
|
80
|
+
# @since 2.0.0.rc.1
|
81
|
+
def validate_relation(metadata)
|
82
|
+
validates_associated(metadata.name) if metadata.validate?
|
83
|
+
end
|
45
84
|
end
|
46
85
|
end
|
47
86
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid #:nodoc:
|
3
3
|
module Validations #:nodoc:
|
4
|
+
|
4
5
|
# Validates whether or not an association is valid or not. Will correctly
|
5
6
|
# handle has one and has many associations.
|
6
7
|
#
|
7
|
-
#
|
8
|
+
# @example Set up the association validations.
|
8
9
|
#
|
9
10
|
# class Person
|
10
11
|
# include Mongoid::Document
|
@@ -19,12 +20,14 @@ module Mongoid #:nodoc:
|
|
19
20
|
# valid. If neither is true then the appropriate errors will be added to
|
20
21
|
# the parent document.
|
21
22
|
#
|
22
|
-
#
|
23
|
+
# @example Validate the association.
|
24
|
+
# validator.validate_each(document, :name, name)
|
23
25
|
#
|
24
|
-
#
|
26
|
+
# @param [ Document ] document The document to validate.
|
27
|
+
# @param [ Symbol ] attribute The relation to validate.
|
28
|
+
# @param [ Object ] value The value of the relation.
|
25
29
|
def validate_each(document, attribute, value)
|
26
|
-
|
27
|
-
return if values.collect { |doc| doc.nil? || doc.valid? }.all?
|
30
|
+
return if value.to_a.collect { |doc| doc.nil? || doc.valid? }.all?
|
28
31
|
document.errors.add(attribute, :invalid, options.merge(:value => value))
|
29
32
|
end
|
30
33
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid #:nodoc:
|
3
3
|
module Validations #:nodoc:
|
4
|
+
|
4
5
|
# Validates whether or not a field is unique against the documents in the
|
5
6
|
# database.
|
6
7
|
#
|
7
|
-
#
|
8
|
+
# @example Define the uniqueness validator.
|
8
9
|
#
|
9
10
|
# class Person
|
10
11
|
# include Mongoid::Document
|
@@ -13,15 +14,26 @@ module Mongoid #:nodoc:
|
|
13
14
|
# validates_uniqueness_of :title
|
14
15
|
# end
|
15
16
|
class UniquenessValidator < ActiveModel::EachValidator
|
17
|
+
|
16
18
|
# Unfortunately, we have to tie Uniqueness validators to a class.
|
17
19
|
def setup(klass)
|
18
20
|
@klass = klass
|
19
21
|
end
|
20
22
|
|
23
|
+
# Validate the document for uniqueness violations.
|
24
|
+
#
|
25
|
+
# @example Validate the document.
|
26
|
+
# validate_each(person, :title, "Sir")
|
27
|
+
#
|
28
|
+
# @param [ Document ] document The document to validate.
|
29
|
+
# @param [ Symbol ] attribute The field to validate on.
|
30
|
+
# @param [ Object ] value The value of the field.
|
31
|
+
#
|
32
|
+
# @todo Durran: This method needs refactoring.
|
21
33
|
def validate_each(document, attribute, value)
|
22
34
|
if document.embedded?
|
23
35
|
return if document._parent.nil?
|
24
|
-
criteria = document._parent.send(document.
|
36
|
+
criteria = document._parent.send(document.metadata.name)
|
25
37
|
# If the parent document embeds_one, no need to validate uniqueness
|
26
38
|
return if criteria.is_a?(Mongoid::Document)
|
27
39
|
criteria = criteria.where(attribute => unique_search_value(value), :_id => {'$ne' => document._id})
|
@@ -45,6 +57,15 @@ module Mongoid #:nodoc:
|
|
45
57
|
end
|
46
58
|
|
47
59
|
protected
|
60
|
+
|
61
|
+
# Determine if the primary key has changed on the document.
|
62
|
+
#
|
63
|
+
# @example Has the key changed?
|
64
|
+
# key_changed?(document)
|
65
|
+
#
|
66
|
+
# @param [ Document ] document The document to check.
|
67
|
+
#
|
68
|
+
# @return [ true, false ] True if changed, false if not.
|
48
69
|
def key_changed?(document)
|
49
70
|
(document.primary_key || {}).each do |key|
|
50
71
|
return true if document.send("#{key}_changed?")
|
data/lib/mongoid/version.rb
CHANGED
data/lib/mongoid/versioning.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
module Mongoid #:nodoc:
|
3
|
+
|
3
4
|
# Include this module to get automatic versioning of root level documents.
|
4
5
|
# This will add a version field to the +Document+ and a has_many association
|
5
6
|
# with all the versions contained in it.
|
@@ -8,34 +9,42 @@ module Mongoid #:nodoc:
|
|
8
9
|
|
9
10
|
included do
|
10
11
|
field :version, :type => Integer, :default => 1
|
11
|
-
embeds_many :versions, :class_name => self.name
|
12
|
+
embeds_many :versions, :class_name => self.name, :validate => false
|
12
13
|
set_callback :save, :before, :revise
|
13
|
-
end
|
14
14
|
|
15
|
-
|
16
|
-
attr_accessor :version_max
|
17
|
-
|
18
|
-
# the number of max_version should >= 0
|
19
|
-
def max_versions(number)
|
20
|
-
self.version_max = number.to_i
|
21
|
-
end
|
15
|
+
delegate :version_max, :to => "self.class"
|
22
16
|
end
|
23
17
|
|
24
18
|
# Create a new version of the +Document+. This will load the previous
|
25
19
|
# document from the database and set it as the next version before saving
|
26
20
|
# the current document. It then increments the version number. If a #max_versions
|
27
21
|
# limit is set in the model and it's exceeded, the oldest version gets discarded.
|
22
|
+
#
|
23
|
+
# @example Revise the document.
|
24
|
+
# person.revise
|
28
25
|
def revise
|
29
26
|
last_version = self.class.first(:conditions => { :_id => id, :version => version })
|
30
27
|
if last_version
|
31
|
-
|
32
|
-
|
33
|
-
if self.class.version_max.present? && ( self.class.version_max >= 0 ) && ( self.versions.length > self.class.version_max )
|
34
|
-
self.versions.shift
|
35
|
-
@attributes['versions'].shift
|
36
|
-
end
|
28
|
+
versions.target << last_version.clone
|
29
|
+
versions.shift if version_max.present? && versions.length > version_max
|
37
30
|
self.version = (version || 1 ) + 1
|
38
|
-
@modifications["versions"] = [
|
31
|
+
@modifications["versions"] = [ nil, versions.to_hash ] if @modifications
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
module ClassMethods #:nodoc:
|
36
|
+
attr_accessor :version_max
|
37
|
+
|
38
|
+
# Sets the maximum number of versions to store.
|
39
|
+
#
|
40
|
+
# @example Set the maximum.
|
41
|
+
# Person.max_versions(5)
|
42
|
+
#
|
43
|
+
# @param [ Integer ] number The maximum number to store.
|
44
|
+
#
|
45
|
+
# @return [ Integer ] The max number of versions.
|
46
|
+
def max_versions(number)
|
47
|
+
self.version_max = number.to_i
|
39
48
|
end
|
40
49
|
end
|
41
50
|
end
|
@@ -5,7 +5,9 @@ class <%= class_name %><%= " < #{options[:parent].classify}" if options[:parent]
|
|
5
5
|
<% if options[:timestamps] -%>
|
6
6
|
include Mongoid::Timestamps
|
7
7
|
<% end -%>
|
8
|
-
|
8
|
+
<% if options[:versioning] -%>
|
9
|
+
include Mongoid::Versioning
|
10
|
+
<% end -%>
|
9
11
|
<% attributes.reject{|attr| attr.reference?}.each do |attribute| -%>
|
10
12
|
field :<%= attribute.name %>, :type => <%= attribute.type_class %>
|
11
13
|
<% end -%>
|
metadata
CHANGED
@@ -1,15 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 62196427
|
5
4
|
prerelease: true
|
6
5
|
segments:
|
7
6
|
- 2
|
8
7
|
- 0
|
9
8
|
- 0
|
10
|
-
-
|
11
|
-
-
|
12
|
-
version: 2.0.0.
|
9
|
+
- rc
|
10
|
+
- 1
|
11
|
+
version: 2.0.0.rc.1
|
13
12
|
platform: ruby
|
14
13
|
authors:
|
15
14
|
- Durran Jordan
|
@@ -17,149 +16,126 @@ autorequire:
|
|
17
16
|
bindir: bin
|
18
17
|
cert_chain: []
|
19
18
|
|
20
|
-
date:
|
19
|
+
date: 2011-01-09 00:00:00 +01:00
|
21
20
|
default_executable:
|
22
21
|
dependencies:
|
23
22
|
- !ruby/object:Gem::Dependency
|
24
|
-
|
23
|
+
name: activemodel
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 7
|
30
29
|
segments:
|
31
30
|
- 3
|
32
31
|
- 0
|
33
32
|
version: "3.0"
|
34
|
-
requirement: *id001
|
35
33
|
type: :runtime
|
36
|
-
name: activemodel
|
37
34
|
prerelease: false
|
35
|
+
version_requirements: *id001
|
38
36
|
- !ruby/object:Gem::Dependency
|
39
|
-
|
37
|
+
name: tzinfo
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
39
|
none: false
|
41
40
|
requirements:
|
42
41
|
- - ~>
|
43
42
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 63
|
45
43
|
segments:
|
46
44
|
- 0
|
47
45
|
- 3
|
48
46
|
- 22
|
49
47
|
version: 0.3.22
|
50
|
-
requirement: *id002
|
51
48
|
type: :runtime
|
52
|
-
name: tzinfo
|
53
49
|
prerelease: false
|
50
|
+
version_requirements: *id002
|
54
51
|
- !ruby/object:Gem::Dependency
|
55
|
-
|
52
|
+
name: will_paginate
|
53
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
56
54
|
none: false
|
57
55
|
requirements:
|
58
56
|
- - ~>
|
59
57
|
- !ruby/object:Gem::Version
|
60
|
-
hash: 961915916
|
61
58
|
segments:
|
62
59
|
- 3
|
63
60
|
- 0
|
64
61
|
- pre
|
65
62
|
version: 3.0.pre
|
66
|
-
requirement: *id003
|
67
63
|
type: :runtime
|
68
|
-
name: will_paginate
|
69
64
|
prerelease: false
|
65
|
+
version_requirements: *id003
|
70
66
|
- !ruby/object:Gem::Dependency
|
71
|
-
|
67
|
+
name: mongo
|
68
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
72
69
|
none: false
|
73
70
|
requirements:
|
74
71
|
- - ~>
|
75
72
|
- !ruby/object:Gem::Version
|
76
|
-
hash: 13
|
77
73
|
segments:
|
78
74
|
- 1
|
79
75
|
- 1
|
80
|
-
|
81
|
-
|
76
|
+
- 5
|
77
|
+
version: 1.1.5
|
82
78
|
type: :runtime
|
83
|
-
name: mongo
|
84
79
|
prerelease: false
|
80
|
+
version_requirements: *id004
|
85
81
|
- !ruby/object:Gem::Dependency
|
86
|
-
|
82
|
+
name: bson_ext
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
87
84
|
none: false
|
88
85
|
requirements:
|
89
86
|
- - ~>
|
90
87
|
- !ruby/object:Gem::Version
|
91
|
-
hash: 13
|
92
88
|
segments:
|
93
89
|
- 1
|
94
90
|
- 1
|
95
|
-
|
96
|
-
|
91
|
+
- 5
|
92
|
+
version: 1.1.5
|
97
93
|
type: :development
|
98
|
-
name: bson_ext
|
99
94
|
prerelease: false
|
95
|
+
version_requirements: *id005
|
100
96
|
- !ruby/object:Gem::Dependency
|
101
|
-
|
97
|
+
name: mocha
|
98
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
102
99
|
none: false
|
103
100
|
requirements:
|
104
101
|
- - "="
|
105
102
|
- !ruby/object:Gem::Version
|
106
|
-
hash: 43
|
107
103
|
segments:
|
108
104
|
- 0
|
109
105
|
- 9
|
110
106
|
- 8
|
111
107
|
version: 0.9.8
|
112
|
-
requirement: *id006
|
113
108
|
type: :development
|
114
|
-
name: mocha
|
115
109
|
prerelease: false
|
110
|
+
version_requirements: *id006
|
116
111
|
- !ruby/object:Gem::Dependency
|
117
|
-
|
112
|
+
name: rspec
|
113
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
118
114
|
none: false
|
119
115
|
requirements:
|
120
|
-
- -
|
116
|
+
- - ~>
|
121
117
|
- !ruby/object:Gem::Version
|
122
|
-
hash: 13
|
123
118
|
segments:
|
124
119
|
- 2
|
125
|
-
-
|
126
|
-
|
127
|
-
version: 2.0.1
|
128
|
-
requirement: *id007
|
120
|
+
- 4
|
121
|
+
version: "2.4"
|
129
122
|
type: :development
|
130
|
-
name: rspec
|
131
123
|
prerelease: false
|
124
|
+
version_requirements: *id007
|
132
125
|
- !ruby/object:Gem::Dependency
|
133
|
-
|
126
|
+
name: watchr
|
127
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
134
128
|
none: false
|
135
129
|
requirements:
|
136
130
|
- - "="
|
137
131
|
- !ruby/object:Gem::Version
|
138
|
-
hash: 7
|
139
132
|
segments:
|
140
133
|
- 0
|
141
134
|
- 6
|
142
135
|
version: "0.6"
|
143
|
-
requirement: *id008
|
144
|
-
type: :development
|
145
|
-
name: watchr
|
146
|
-
prerelease: false
|
147
|
-
- !ruby/object:Gem::Dependency
|
148
|
-
version_requirements: &id009 !ruby/object:Gem::Requirement
|
149
|
-
none: false
|
150
|
-
requirements:
|
151
|
-
- - "="
|
152
|
-
- !ruby/object:Gem::Version
|
153
|
-
hash: 29
|
154
|
-
segments:
|
155
|
-
- 0
|
156
|
-
- 0
|
157
|
-
- 1
|
158
|
-
version: 0.0.1
|
159
|
-
requirement: *id009
|
160
136
|
type: :development
|
161
|
-
name: ruby-debug-wrapper
|
162
137
|
prerelease: false
|
138
|
+
version_requirements: *id008
|
163
139
|
description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written in Ruby.
|
164
140
|
email:
|
165
141
|
- durran@gmail.com
|
@@ -178,24 +154,13 @@ files:
|
|
178
154
|
- lib/config/locales/hu.yml
|
179
155
|
- lib/config/locales/it.yml
|
180
156
|
- lib/config/locales/kr.yml
|
157
|
+
- lib/config/locales/nl.yml
|
181
158
|
- lib/config/locales/pl.yml
|
182
159
|
- lib/config/locales/pt-br.yml
|
183
160
|
- lib/config/locales/pt.yml
|
184
161
|
- lib/config/locales/ro.yml
|
185
162
|
- lib/config/locales/sv.yml
|
186
163
|
- lib/config/locales/zh-CN.yml
|
187
|
-
- lib/mongoid/associations/embedded_in.rb
|
188
|
-
- lib/mongoid/associations/embeds_many.rb
|
189
|
-
- lib/mongoid/associations/embeds_one.rb
|
190
|
-
- lib/mongoid/associations/foreign_key.rb
|
191
|
-
- lib/mongoid/associations/meta_data.rb
|
192
|
-
- lib/mongoid/associations/options.rb
|
193
|
-
- lib/mongoid/associations/proxy.rb
|
194
|
-
- lib/mongoid/associations/referenced_in.rb
|
195
|
-
- lib/mongoid/associations/references_many.rb
|
196
|
-
- lib/mongoid/associations/references_many_as_array.rb
|
197
|
-
- lib/mongoid/associations/references_one.rb
|
198
|
-
- lib/mongoid/associations.rb
|
199
164
|
- lib/mongoid/atomicity.rb
|
200
165
|
- lib/mongoid/attributes.rb
|
201
166
|
- lib/mongoid/callbacks.rb
|
@@ -206,6 +171,7 @@ files:
|
|
206
171
|
- lib/mongoid/collections/slaves.rb
|
207
172
|
- lib/mongoid/collections.rb
|
208
173
|
- lib/mongoid/components.rb
|
174
|
+
- lib/mongoid/config/database.rb
|
209
175
|
- lib/mongoid/config.rb
|
210
176
|
- lib/mongoid/contexts/enumerable/sort.rb
|
211
177
|
- lib/mongoid/contexts/enumerable.rb
|
@@ -213,13 +179,18 @@ files:
|
|
213
179
|
- lib/mongoid/contexts/mongo.rb
|
214
180
|
- lib/mongoid/contexts/paging.rb
|
215
181
|
- lib/mongoid/contexts.rb
|
182
|
+
- lib/mongoid/copyable.rb
|
216
183
|
- lib/mongoid/criteria.rb
|
217
184
|
- lib/mongoid/criterion/complex.rb
|
185
|
+
- lib/mongoid/criterion/creational.rb
|
186
|
+
- lib/mongoid/criterion/destructive.rb
|
218
187
|
- lib/mongoid/criterion/exclusion.rb
|
219
188
|
- lib/mongoid/criterion/inclusion.rb
|
189
|
+
- lib/mongoid/criterion/inspection.rb
|
220
190
|
- lib/mongoid/criterion/optional.rb
|
221
191
|
- lib/mongoid/criterion/selector.rb
|
222
192
|
- lib/mongoid/cursor.rb
|
193
|
+
- lib/mongoid/default_scope.rb
|
223
194
|
- lib/mongoid/deprecation.rb
|
224
195
|
- lib/mongoid/dirty.rb
|
225
196
|
- lib/mongoid/document.rb
|
@@ -234,8 +205,6 @@ files:
|
|
234
205
|
- lib/mongoid/errors/unsupported_version.rb
|
235
206
|
- lib/mongoid/errors/validations.rb
|
236
207
|
- lib/mongoid/errors.rb
|
237
|
-
- lib/mongoid/extensions/array/accessors.rb
|
238
|
-
- lib/mongoid/extensions/array/assimilation.rb
|
239
208
|
- lib/mongoid/extensions/array/conversions.rb
|
240
209
|
- lib/mongoid/extensions/array/parentization.rb
|
241
210
|
- lib/mongoid/extensions/big_decimal/conversions.rb
|
@@ -245,14 +214,14 @@ files:
|
|
245
214
|
- lib/mongoid/extensions/datetime/conversions.rb
|
246
215
|
- lib/mongoid/extensions/false_class/equality.rb
|
247
216
|
- lib/mongoid/extensions/float/conversions.rb
|
248
|
-
- lib/mongoid/extensions/hash/accessors.rb
|
249
|
-
- lib/mongoid/extensions/hash/assimilation.rb
|
250
217
|
- lib/mongoid/extensions/hash/conversions.rb
|
251
218
|
- lib/mongoid/extensions/hash/criteria_helpers.rb
|
252
219
|
- lib/mongoid/extensions/hash/scoping.rb
|
253
220
|
- lib/mongoid/extensions/integer/conversions.rb
|
254
|
-
- lib/mongoid/extensions/nil/
|
221
|
+
- lib/mongoid/extensions/nil/collectionization.rb
|
255
222
|
- lib/mongoid/extensions/object/conversions.rb
|
223
|
+
- lib/mongoid/extensions/object/reflections.rb
|
224
|
+
- lib/mongoid/extensions/object/yoda.rb
|
256
225
|
- lib/mongoid/extensions/object_id/conversions.rb
|
257
226
|
- lib/mongoid/extensions/proc/scoping.rb
|
258
227
|
- lib/mongoid/extensions/set/conversions.rb
|
@@ -271,6 +240,7 @@ files:
|
|
271
240
|
- lib/mongoid/hierarchy.rb
|
272
241
|
- lib/mongoid/identity.rb
|
273
242
|
- lib/mongoid/indexes.rb
|
243
|
+
- lib/mongoid/inspection.rb
|
274
244
|
- lib/mongoid/javascript/functions.yml
|
275
245
|
- lib/mongoid/javascript.rb
|
276
246
|
- lib/mongoid/json.rb
|
@@ -288,12 +258,13 @@ files:
|
|
288
258
|
- lib/mongoid/matchers/nin.rb
|
289
259
|
- lib/mongoid/matchers/size.rb
|
290
260
|
- lib/mongoid/matchers.rb
|
291
|
-
- lib/mongoid/memoization.rb
|
292
261
|
- lib/mongoid/modifiers/command.rb
|
293
262
|
- lib/mongoid/modifiers/inc.rb
|
294
263
|
- lib/mongoid/modifiers.rb
|
264
|
+
- lib/mongoid/multi_database.rb
|
295
265
|
- lib/mongoid/multi_parameter_attributes.rb
|
296
266
|
- lib/mongoid/named_scope.rb
|
267
|
+
- lib/mongoid/nested_attributes.rb
|
297
268
|
- lib/mongoid/paranoia.rb
|
298
269
|
- lib/mongoid/paths.rb
|
299
270
|
- lib/mongoid/persistence/command.rb
|
@@ -307,6 +278,50 @@ files:
|
|
307
278
|
- lib/mongoid/railtie.rb
|
308
279
|
- lib/mongoid/railties/database.rake
|
309
280
|
- lib/mongoid/railties/document.rb
|
281
|
+
- lib/mongoid/relations/accessors.rb
|
282
|
+
- lib/mongoid/relations/auto_save.rb
|
283
|
+
- lib/mongoid/relations/binding.rb
|
284
|
+
- lib/mongoid/relations/bindings/embedded/in.rb
|
285
|
+
- lib/mongoid/relations/bindings/embedded/many.rb
|
286
|
+
- lib/mongoid/relations/bindings/embedded/one.rb
|
287
|
+
- lib/mongoid/relations/bindings/referenced/in.rb
|
288
|
+
- lib/mongoid/relations/bindings/referenced/many.rb
|
289
|
+
- lib/mongoid/relations/bindings/referenced/many_to_many.rb
|
290
|
+
- lib/mongoid/relations/bindings/referenced/one.rb
|
291
|
+
- lib/mongoid/relations/bindings.rb
|
292
|
+
- lib/mongoid/relations/builder.rb
|
293
|
+
- lib/mongoid/relations/builders/embedded/in.rb
|
294
|
+
- lib/mongoid/relations/builders/embedded/many.rb
|
295
|
+
- lib/mongoid/relations/builders/embedded/one.rb
|
296
|
+
- lib/mongoid/relations/builders/nested_attributes/many.rb
|
297
|
+
- lib/mongoid/relations/builders/nested_attributes/one.rb
|
298
|
+
- lib/mongoid/relations/builders/referenced/in.rb
|
299
|
+
- lib/mongoid/relations/builders/referenced/many.rb
|
300
|
+
- lib/mongoid/relations/builders/referenced/many_to_many.rb
|
301
|
+
- lib/mongoid/relations/builders/referenced/one.rb
|
302
|
+
- lib/mongoid/relations/builders.rb
|
303
|
+
- lib/mongoid/relations/cascading/delete.rb
|
304
|
+
- lib/mongoid/relations/cascading/destroy.rb
|
305
|
+
- lib/mongoid/relations/cascading/nullify.rb
|
306
|
+
- lib/mongoid/relations/cascading/strategy.rb
|
307
|
+
- lib/mongoid/relations/cascading.rb
|
308
|
+
- lib/mongoid/relations/cyclic.rb
|
309
|
+
- lib/mongoid/relations/embedded/in.rb
|
310
|
+
- lib/mongoid/relations/embedded/many.rb
|
311
|
+
- lib/mongoid/relations/embedded/one.rb
|
312
|
+
- lib/mongoid/relations/macros.rb
|
313
|
+
- lib/mongoid/relations/many.rb
|
314
|
+
- lib/mongoid/relations/metadata.rb
|
315
|
+
- lib/mongoid/relations/nested_builder.rb
|
316
|
+
- lib/mongoid/relations/one.rb
|
317
|
+
- lib/mongoid/relations/polymorphic.rb
|
318
|
+
- lib/mongoid/relations/proxy.rb
|
319
|
+
- lib/mongoid/relations/referenced/in.rb
|
320
|
+
- lib/mongoid/relations/referenced/many.rb
|
321
|
+
- lib/mongoid/relations/referenced/many_to_many.rb
|
322
|
+
- lib/mongoid/relations/referenced/one.rb
|
323
|
+
- lib/mongoid/relations/reflections.rb
|
324
|
+
- lib/mongoid/relations.rb
|
310
325
|
- lib/mongoid/safe.rb
|
311
326
|
- lib/mongoid/safety.rb
|
312
327
|
- lib/mongoid/scope.rb
|
@@ -326,6 +341,7 @@ files:
|
|
326
341
|
- lib/rails/mongoid.rb
|
327
342
|
- MIT_LICENSE
|
328
343
|
- README.rdoc
|
344
|
+
- Rakefile
|
329
345
|
has_rdoc: true
|
330
346
|
homepage: http://mongoid.org
|
331
347
|
licenses: []
|
@@ -340,7 +356,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
340
356
|
requirements:
|
341
357
|
- - ">="
|
342
358
|
- !ruby/object:Gem::Version
|
343
|
-
hash:
|
359
|
+
hash: 1989103359598370074
|
344
360
|
segments:
|
345
361
|
- 0
|
346
362
|
version: "0"
|
@@ -349,7 +365,6 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
349
365
|
requirements:
|
350
366
|
- - ">="
|
351
367
|
- !ruby/object:Gem::Version
|
352
|
-
hash: 23
|
353
368
|
segments:
|
354
369
|
- 1
|
355
370
|
- 3
|
@@ -361,6 +376,6 @@ rubyforge_project: mongoid
|
|
361
376
|
rubygems_version: 1.3.7
|
362
377
|
signing_key:
|
363
378
|
specification_version: 3
|
364
|
-
summary:
|
379
|
+
summary: Elegant Persistance in Ruby for MongoDB.
|
365
380
|
test_files: []
|
366
381
|
|