mongoid 2.1.4 → 2.1.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,6 +35,7 @@ module Mongoid #:nodoc:
35
35
  # @since 2.1.0
36
36
  def set(modifications)
37
37
  modifications.each_pair do |field, value|
38
+ next if field == "_id"
38
39
  sets.update(field => value)
39
40
  fields << field.split(".", 2)[0]
40
41
  end
@@ -79,7 +79,7 @@ namespace :db do
79
79
 
80
80
  desc 'Create the indexes defined on your mongoid models'
81
81
  task :create_indexes => :environment do
82
- ::Rails::Mongoid.index_children(get_mongoid_models)
82
+ ::Rails::Mongoid.create_indexes("app/models/**/*.rb")
83
83
  end
84
84
 
85
85
  def convert_ids(obj)
@@ -69,7 +69,7 @@ module Mongoid # :nodoc:
69
69
  #
70
70
  # @since 2.0.0.rc.1
71
71
  def embedded_many?
72
- @embedded_many ||= (metadata && metadata.macro == :embeds_many)
72
+ metadata && metadata.macro == :embeds_many
73
73
  end
74
74
 
75
75
  # Determine if the document is part of an embeds_one relation.
@@ -81,7 +81,7 @@ module Mongoid # :nodoc:
81
81
  #
82
82
  # @since 2.0.0.rc.1
83
83
  def embedded_one?
84
- @embedded_one ||= (metadata && metadata.macro == :embeds_one)
84
+ metadata && metadata.macro == :embeds_one
85
85
  end
86
86
 
87
87
  # Determine if the document is part of an references_many relation.
@@ -93,7 +93,7 @@ module Mongoid # :nodoc:
93
93
  #
94
94
  # @since 2.0.0.rc.1
95
95
  def referenced_many?
96
- @referenced_many ||= (metadata && metadata.macro == :references_many)
96
+ metadata && metadata.macro == :references_many
97
97
  end
98
98
 
99
99
  # Determine if the document is part of an references_one relation.
@@ -105,7 +105,7 @@ module Mongoid # :nodoc:
105
105
  #
106
106
  # @since 2.0.0.rc.1
107
107
  def referenced_one?
108
- @referenced_one ||= (metadata && metadata.macro == :references_one)
108
+ metadata && metadata.macro == :references_one
109
109
  end
110
110
  end
111
111
  end
@@ -124,8 +124,8 @@ module Mongoid # :nodoc:
124
124
  def delete(document)
125
125
  target.delete_one(document).tap do |doc|
126
126
  if doc && !binding?
127
- unbind_one(doc)
128
127
  doc.delete(:suppress => true)
128
+ unbind_one(doc)
129
129
  end
130
130
  reindex
131
131
  end
@@ -374,8 +374,8 @@ module Mongoid # :nodoc:
374
374
  criteria.size.tap do
375
375
  criteria.each do |doc|
376
376
  target.delete_one(doc)
377
- unbind_one(doc)
378
377
  doc.send(method, :suppress => true)
378
+ unbind_one(doc)
379
379
  end
380
380
  reindex
381
381
  end
@@ -80,7 +80,8 @@ module Mongoid #:nodoc:
80
80
  #
81
81
  # @since 2.0.0
82
82
  def respond_to?(name, include_private = false)
83
- [].respond_to?(name, include_private) || super
83
+ [].respond_to?(name, include_private) ||
84
+ klass.respond_to?(name, include_private) || super
84
85
  end
85
86
 
86
87
  # This is public access to the relation's criteria.
@@ -9,7 +9,7 @@ module Mongoid # :nodoc:
9
9
  # We undefine most methods to get them sent through to the target.
10
10
  instance_methods.each do |method|
11
11
  undef_method(method) unless
12
- method =~ /(^__|^send$|^object_id$|^extend$|^tap$)/
12
+ method =~ /(^__|^send$|^object_id$|^extend$|^respond_to\?$|^tap$)/
13
13
  end
14
14
 
15
15
  attr_accessor :base, :loaded, :metadata, :target
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module Mongoid #:nodoc
3
- VERSION = "2.1.4"
3
+ VERSION = "2.1.5"
4
4
  end
@@ -3,23 +3,24 @@ module Rails #:nodoc:
3
3
  module Mongoid #:nodoc:
4
4
  extend self
5
5
 
6
- # Recursive function to create all the indexes for the model, then
7
- # potentially and subclass of the model since both are still root
8
- # documents in the hierarchy.
9
- #
10
- # Note there is a tricky naming scheme going on here that needs to be
11
- # revisisted. Module.descendants vs Class.descendents is way too
12
- # confusing.
13
- #
14
- # @example Index the children.
15
- # Rails::Mongoid.index_children(classes)
16
- #
17
- # @param [ Array<Class> ] children The child model classes.
18
- def index_children(children)
19
- children.each do |model|
20
- Logger.new($stdout).info("Generating indexes for #{model}")
21
- model.create_indexes
22
- index_children(model.descendants)
6
+ # Create indexes for each model given the provided pattern and the class is
7
+ # not embedded.
8
+ #
9
+ # @example Create all the indexes.
10
+ # Rails::Mongoid.create_indexes("app/models/**/*.rb")
11
+ #
12
+ # @param [ String ] pattern The file matching pattern.
13
+ #
14
+ # @return [ Array<String> ] The file names.
15
+ #
16
+ # @since 2.1.0
17
+ def create_indexes(pattern)
18
+ Dir.glob(pattern).each do |file|
19
+ model = determine_model(file)
20
+ if model
21
+ Logger.new($stdout).info("Generating indexes for #{model}")
22
+ model.create_indexes
23
+ end
23
24
  end
24
25
  end
25
26
 
@@ -54,5 +55,26 @@ module Rails #:nodoc:
54
55
  def load_model(file)
55
56
  require_dependency(file)
56
57
  end
58
+
59
+ # Given the provided file name, determine the model and return the class.
60
+ #
61
+ # @example Determine the model from the file.
62
+ # Rails::Mongoid.determine_model("app/models/person.rb")
63
+ #
64
+ # @param [ String ] file The filename.
65
+ #
66
+ # @return [ Class ] The model.
67
+ #
68
+ # @since 2.1.0
69
+ def determine_model(file)
70
+ model_path = file[0..-4].split('/')[2..-1]
71
+ begin
72
+ klass = model_path.map { |path| path.camelize }.join('::').constantize
73
+ if klass.ancestors.include?(::Mongoid::Document) && !klass.embedded
74
+ return klass
75
+ end
76
+ rescue => e
77
+ end
78
+ end
57
79
  end
58
80
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.4
4
+ version: 2.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-03 00:00:00.000000000Z
12
+ date: 2011-08-05 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activemodel
16
- requirement: &70122215923500 !ruby/object:Gem::Requirement
16
+ requirement: &70194026936900 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '3.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70122215923500
24
+ version_requirements: *70194026936900
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: tzinfo
27
- requirement: &70122215922340 !ruby/object:Gem::Requirement
27
+ requirement: &70194026936180 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 0.3.22
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70122215922340
35
+ version_requirements: *70194026936180
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: mongo
38
- requirement: &70122215921340 !ruby/object:Gem::Requirement
38
+ requirement: &70194026935100 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '1.3'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *70122215921340
46
+ version_requirements: *70194026935100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rdoc
49
- requirement: &70122215920320 !ruby/object:Gem::Requirement
49
+ requirement: &70194026934200 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 3.5.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70122215920320
57
+ version_requirements: *70194026934200
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: bson_ext
60
- requirement: &70122215918960 !ruby/object:Gem::Requirement
60
+ requirement: &70194026933020 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '1.3'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70122215918960
68
+ version_requirements: *70194026933020
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: mocha
71
- requirement: &70122215917980 !ruby/object:Gem::Requirement
71
+ requirement: &70194026932080 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ~>
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: 0.9.8
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70122215917980
79
+ version_requirements: *70194026932080
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rspec
82
- requirement: &70122215916160 !ruby/object:Gem::Requirement
82
+ requirement: &70194026931080 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ~>
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '2.6'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *70122215916160
90
+ version_requirements: *70194026931080
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: watchr
93
- requirement: &70122215915360 !ruby/object:Gem::Requirement
93
+ requirement: &70194026929800 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ~>
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0.6'
99
99
  type: :development
100
100
  prerelease: false
101
- version_requirements: *70122215915360
101
+ version_requirements: *70194026929800
102
102
  description: Mongoid is an ODM (Object Document Mapper) Framework for MongoDB, written
103
103
  in Ruby.
104
104
  email:
@@ -378,7 +378,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
378
378
  version: '0'
379
379
  segments:
380
380
  - 0
381
- hash: -2177920959190561279
381
+ hash: 3142306228316146123
382
382
  required_rubygems_version: !ruby/object:Gem::Requirement
383
383
  none: false
384
384
  requirements: