mongoid 4.0.2 → 5.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +66 -1
  3. data/README.md +14 -13
  4. data/lib/config/locales/en.yml +28 -28
  5. data/lib/mongoid.rb +28 -21
  6. data/lib/mongoid/atomic.rb +2 -4
  7. data/lib/mongoid/attributes.rb +7 -7
  8. data/lib/mongoid/attributes/processing.rb +4 -1
  9. data/lib/mongoid/attributes/readonly.rb +2 -2
  10. data/lib/mongoid/changeable.rb +4 -6
  11. data/lib/mongoid/clients.rb +142 -0
  12. data/lib/mongoid/clients/factory.rb +78 -0
  13. data/lib/mongoid/{sessions → clients}/options.rb +30 -19
  14. data/lib/mongoid/{sessions → clients}/storage_options.rb +27 -13
  15. data/lib/mongoid/{sessions → clients}/thread_options.rb +6 -3
  16. data/lib/mongoid/clients/validators.rb +2 -0
  17. data/lib/mongoid/{sessions → clients}/validators/storage.rb +5 -2
  18. data/lib/mongoid/composable.rb +3 -3
  19. data/lib/mongoid/config.rb +39 -41
  20. data/lib/mongoid/config/environment.rb +1 -1
  21. data/lib/mongoid/config/validators.rb +1 -1
  22. data/lib/mongoid/config/validators/{session.rb → client.rb} +31 -28
  23. data/lib/mongoid/contextual/aggregable/mongo.rb +1 -1
  24. data/lib/mongoid/contextual/atomic.rb +11 -11
  25. data/lib/mongoid/contextual/command.rb +9 -6
  26. data/lib/mongoid/contextual/geo_near.rb +17 -1
  27. data/lib/mongoid/contextual/map_reduce.rb +12 -11
  28. data/lib/mongoid/contextual/memory.rb +2 -5
  29. data/lib/mongoid/contextual/mongo.rb +92 -82
  30. data/lib/mongoid/contextual/none.rb +13 -0
  31. data/lib/mongoid/copyable.rb +6 -1
  32. data/lib/mongoid/criteria.rb +36 -3
  33. data/lib/mongoid/document.rb +3 -4
  34. data/lib/mongoid/errors.rb +6 -6
  35. data/lib/mongoid/errors/{mixed_session_configuration.rb → mixed_client_configuration.rb} +5 -5
  36. data/lib/mongoid/errors/no_client_config.rb +22 -0
  37. data/lib/mongoid/errors/{no_session_database.rb → no_client_database.rb} +4 -4
  38. data/lib/mongoid/errors/{no_session_hosts.rb → no_client_hosts.rb} +4 -4
  39. data/lib/mongoid/errors/{no_sessions_config.rb → no_clients_config.rb} +4 -4
  40. data/lib/mongoid/errors/no_default_client.rb +23 -0
  41. data/lib/mongoid/extensions/hash.rb +5 -1
  42. data/lib/mongoid/extensions/object.rb +3 -2
  43. data/lib/mongoid/extensions/set.rb +5 -5
  44. data/lib/mongoid/factory.rb +4 -2
  45. data/lib/mongoid/fields.rb +7 -2
  46. data/lib/mongoid/findable.rb +4 -1
  47. data/lib/mongoid/indexable.rb +15 -9
  48. data/lib/mongoid/persistable.rb +1 -2
  49. data/lib/mongoid/persistable/creatable.rb +2 -2
  50. data/lib/mongoid/persistable/deletable.rb +3 -3
  51. data/lib/mongoid/persistable/incrementable.rb +1 -1
  52. data/lib/mongoid/persistable/logical.rb +1 -1
  53. data/lib/mongoid/persistable/poppable.rb +1 -1
  54. data/lib/mongoid/persistable/pullable.rb +2 -2
  55. data/lib/mongoid/persistable/pushable.rb +2 -2
  56. data/lib/mongoid/persistable/renamable.rb +1 -1
  57. data/lib/mongoid/persistable/settable.rb +1 -1
  58. data/lib/mongoid/persistable/unsettable.rb +1 -1
  59. data/lib/mongoid/persistable/updatable.rb +2 -2
  60. data/lib/mongoid/persistable/upsertable.rb +1 -1
  61. data/lib/mongoid/query_cache.rb +98 -104
  62. data/lib/mongoid/railtie.rb +1 -21
  63. data/lib/mongoid/railties/database.rake +1 -1
  64. data/lib/mongoid/relations/builders.rb +3 -1
  65. data/lib/mongoid/relations/counter_cache.rb +1 -1
  66. data/lib/mongoid/relations/embedded/batchable.rb +3 -10
  67. data/lib/mongoid/relations/embedded/many.rb +4 -2
  68. data/lib/mongoid/relations/many.rb +1 -0
  69. data/lib/mongoid/relations/proxy.rb +6 -6
  70. data/lib/mongoid/relations/referenced/many.rb +2 -1
  71. data/lib/mongoid/relations/targets/enumerable.rb +11 -11
  72. data/lib/mongoid/relations/touchable.rb +1 -1
  73. data/lib/mongoid/reloadable.rb +2 -2
  74. data/lib/mongoid/scopable.rb +6 -17
  75. data/lib/mongoid/selectable.rb +1 -36
  76. data/lib/mongoid/serializable.rb +2 -2
  77. data/lib/mongoid/stateful.rb +0 -1
  78. data/lib/mongoid/tasks/database.rake +2 -2
  79. data/lib/mongoid/tasks/database.rb +23 -16
  80. data/lib/mongoid/threaded.rb +54 -33
  81. data/lib/mongoid/threaded/lifecycle.rb +21 -16
  82. data/lib/mongoid/traversable.rb +16 -1
  83. data/lib/mongoid/validatable.rb +1 -1
  84. data/lib/mongoid/validatable/queryable.rb +1 -1
  85. data/lib/mongoid/validatable/uniqueness.rb +3 -20
  86. data/lib/mongoid/version.rb +1 -1
  87. data/lib/rails/generators/mongoid/config/templates/mongoid.yml +91 -57
  88. data/lib/rails/mongoid.rb +2 -2
  89. data/spec/app/models/audio.rb +1 -1
  90. data/spec/app/models/band.rb +1 -0
  91. data/spec/app/models/company.rb +5 -0
  92. data/spec/app/models/label.rb +7 -0
  93. data/spec/app/models/pub.rb +6 -0
  94. data/spec/app/models/staff.rb +7 -0
  95. data/spec/app/models/store_as_dup_test1.rb +5 -0
  96. data/spec/app/models/store_as_dup_test2.rb +5 -0
  97. data/spec/config/mongoid.yml +7 -25
  98. data/spec/mongoid/atomic/paths_spec.rb +3 -11
  99. data/spec/mongoid/attributes/nested_spec.rb +16 -16
  100. data/spec/mongoid/attributes/readonly_spec.rb +80 -18
  101. data/spec/mongoid/attributes_spec.rb +3 -3
  102. data/spec/mongoid/changeable_spec.rb +70 -0
  103. data/spec/mongoid/clients/factory_spec.rb +284 -0
  104. data/spec/mongoid/{sessions → clients}/options_spec.rb +4 -6
  105. data/spec/mongoid/clients_spec.rb +739 -0
  106. data/spec/mongoid/config/environment_spec.rb +14 -11
  107. data/spec/mongoid/config_spec.rb +33 -48
  108. data/spec/mongoid/contextual/atomic_spec.rb +1 -17
  109. data/spec/mongoid/contextual/geo_near_spec.rb +35 -0
  110. data/spec/mongoid/contextual/mongo_spec.rb +26 -83
  111. data/spec/mongoid/contextual/none_spec.rb +15 -0
  112. data/spec/mongoid/copyable_spec.rb +35 -1
  113. data/spec/mongoid/criteria/findable_spec.rb +197 -0
  114. data/spec/mongoid/criteria/modifiable_spec.rb +7 -29
  115. data/spec/mongoid/criteria_spec.rb +74 -91
  116. data/spec/mongoid/document_spec.rb +1 -1
  117. data/spec/mongoid/errors/{mixed_session_configuration_spec.rb → mixed_client_configuration_spec.rb} +1 -1
  118. data/spec/mongoid/errors/{no_session_config_spec.rb → no_client_config_spec.rb} +4 -4
  119. data/spec/mongoid/errors/{no_session_database_spec.rb → no_client_database_spec.rb} +4 -4
  120. data/spec/mongoid/errors/{no_session_hosts_spec.rb → no_client_hosts_spec.rb} +3 -3
  121. data/spec/mongoid/errors/{no_sessions_config_spec.rb → no_clients_config_spec.rb} +2 -2
  122. data/spec/mongoid/fields/localized_spec.rb +1 -0
  123. data/spec/mongoid/fields_spec.rb +1 -0
  124. data/spec/mongoid/findable_spec.rb +2 -23
  125. data/spec/mongoid/indexable_spec.rb +12 -8
  126. data/spec/mongoid/interceptable_spec.rb +15 -0
  127. data/spec/mongoid/persistable/settable_spec.rb +16 -0
  128. data/spec/mongoid/persistable/updatable_spec.rb +3 -2
  129. data/spec/mongoid/persistable_spec.rb +4 -4
  130. data/spec/mongoid/query_cache_spec.rb +13 -8
  131. data/spec/mongoid/relations/auto_save_spec.rb +1 -1
  132. data/spec/mongoid/relations/counter_cache_spec.rb +34 -0
  133. data/spec/mongoid/relations/eager/belongs_to_spec.rb +9 -0
  134. data/spec/mongoid/relations/eager/has_and_belongs_to_many_spec.rb +3 -3
  135. data/spec/mongoid/relations/embedded/many_spec.rb +123 -1
  136. data/spec/mongoid/relations/embedded/one_spec.rb +3 -3
  137. data/spec/mongoid/relations/proxy_spec.rb +28 -0
  138. data/spec/mongoid/relations/referenced/in_spec.rb +1 -1
  139. data/spec/mongoid/relations/referenced/many_spec.rb +47 -23
  140. data/spec/mongoid/relations/referenced/many_to_many_spec.rb +1 -1
  141. data/spec/mongoid/relations/referenced/one_spec.rb +1 -1
  142. data/spec/mongoid/relations/targets/enumerable_spec.rb +9 -2
  143. data/spec/mongoid/reloadable_spec.rb +6 -6
  144. data/spec/mongoid/scopable_spec.rb +41 -28
  145. data/spec/mongoid/selectable_spec.rb +6 -16
  146. data/spec/mongoid/tasks/database_rake_spec.rb +13 -13
  147. data/spec/mongoid/tasks/database_spec.rb +2 -2
  148. data/spec/mongoid/threaded_spec.rb +0 -7
  149. data/spec/mongoid/traversable_spec.rb +2 -2
  150. data/spec/mongoid/validatable/uniqueness_spec.rb +30 -1
  151. data/spec/mongoid_spec.rb +13 -15
  152. data/spec/rails/mongoid_spec.rb +13 -4
  153. data/spec/spec_helper.rb +44 -27
  154. data/spec/support/authorization.rb +12 -0
  155. data/spec/support/expectations.rb +14 -0
  156. metadata +52 -59
  157. data/lib/mongoid/contextual/find_and_modify.rb +0 -69
  158. data/lib/mongoid/contextual/text_search.rb +0 -178
  159. data/lib/mongoid/criteria/#findable.rb# +0 -141
  160. data/lib/mongoid/errors/no_default_session.rb +0 -23
  161. data/lib/mongoid/errors/no_session_config.rb +0 -22
  162. data/lib/mongoid/log_subscriber.rb +0 -55
  163. data/lib/mongoid/positional.rb +0 -71
  164. data/lib/mongoid/sessions.rb +0 -125
  165. data/lib/mongoid/sessions/factory.rb +0 -131
  166. data/lib/mongoid/sessions/mongo_uri.rb +0 -93
  167. data/lib/mongoid/sessions/validators.rb +0 -2
  168. data/lib/mongoid/support/query_counter.rb +0 -23
  169. data/spec/helpers.rb +0 -18
  170. data/spec/mongoid/#atomic_spec.rb# +0 -365
  171. data/spec/mongoid/contextual/find_and_modify_spec.rb +0 -220
  172. data/spec/mongoid/contextual/text_search_spec.rb +0 -209
  173. data/spec/mongoid/log_subscriber_spec.rb +0 -75
  174. data/spec/mongoid/positional_spec.rb +0 -222
  175. data/spec/mongoid/sessions/factory_spec.rb +0 -333
  176. data/spec/mongoid/sessions/mongo_uri_spec.rb +0 -103
  177. data/spec/mongoid/sessions_spec.rb +0 -1252
@@ -1,69 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid
3
- module Contextual
4
- class FindAndModify
5
- include Command
6
-
7
- # @attribute [r] criteria The criteria for the context.
8
- # @attribute [r] options The command options.
9
- # @attribute [r] update The updates.
10
- # @attribute [r] query The Moped query.
11
- attr_reader :criteria, :options, :update, :query
12
-
13
- # Initialize the find and modify command, used for MongoDB's
14
- # $findAndModify.
15
- #
16
- # @example Initialize the command.
17
- # FindAndModify.new(criteria, { "$set" => { likes: 1 }})
18
- #
19
- # @param [ Criteria ] criteria The criteria.
20
- # @param [ Hash ] update The updates.
21
- # @param [ Hash ] options The command options.
22
- #
23
- # @option options [ true, false ] :new Return the updated document.
24
- # @option options [ true, false ] :remove Delete the first document.
25
- # @option options [ true, false ] :upsert Create the document if it doesn't exist.
26
- #
27
- # @since 3.0.0
28
- def initialize(collection, criteria, update, options = {})
29
- @collection, @criteria, @options, @update =
30
- collection, criteria, options, update.mongoize
31
- @query = collection.find(criteria.selector)
32
- apply_criteria_options
33
- end
34
-
35
- # Get the result of the $findAndModify.
36
- #
37
- # @example Get the result.
38
- # find_and_modify.result
39
- #
40
- # @return [ Hash ] The result of the command.
41
- #
42
- # @since 3.0.0
43
- def result
44
- query.modify(update, options)
45
- end
46
-
47
- private
48
-
49
- # Apply criteria specific options - query, sort, fields.
50
- #
51
- # @api private
52
- #
53
- # @example Apply the criteria options
54
- # find_and_modify.apply_criteria_options
55
- #
56
- # @return [ nil ] Nothing.
57
- #
58
- # @since 3.0.0
59
- def apply_criteria_options
60
- if spec = criteria.options[:sort]
61
- query.sort(spec)
62
- end
63
- if spec = criteria.options[:fields]
64
- query.select(spec)
65
- end
66
- end
67
- end
68
- end
69
- end
@@ -1,178 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid
3
- module Contextual
4
-
5
- # Wraps behaviour around a lazy text search command.
6
- #
7
- # @since 4.0.0
8
- class TextSearch
9
- include Enumerable
10
- include Command
11
-
12
- delegate :[], to: :results
13
- delegate :==, :empty?, to: :entries
14
-
15
- # Iterate over the results of the text search command.
16
- #
17
- # @example Iterate over the results.
18
- # text_search.each do |doc|
19
- # #...
20
- # end
21
- #
22
- # @return [ Enumerator ] The enumerator.
23
- #
24
- # @since 4.0.0
25
- def each
26
- if block_given?
27
- documents.each do |doc|
28
- yield doc
29
- end
30
- else
31
- to_enum
32
- end
33
- end
34
-
35
- # Instantiate a new text search lazy proxy.
36
- #
37
- # @example Instantiate the text search.
38
- # TextSearch.new(collection, criteria, "test")
39
- #
40
- # @param [ Moped::Collection ] collection The collection to execute on.
41
- # @param [ Criteria ] criteria The criteria to filter results.
42
- # @param [ String ] search_string The search string.
43
- #
44
- # @since 4.0.0
45
- def initialize(collection, criteria, search_string)
46
- @collection, @criteria = collection, criteria
47
- command[:text] = collection.name.to_s
48
- command[:search] = search_string
49
- apply_criteria_options
50
- end
51
-
52
- # Inspect the text search object.
53
- #
54
- # @example Inspect the text search.
55
- # text_search.inspect
56
- #
57
- # @return [ String ] The inspection.
58
- #
59
- # @since 4.0.0
60
- def inspect
61
- %Q{#<Mongoid::Contextual::TextSearch
62
- selector: #{criteria.selector.inspect}
63
- class: #{criteria.klass}
64
- search: #{command[:search]}
65
- filter: #{command[:filter] || "N/A"}
66
- project: #{command[:project] || "N/A"}
67
- limit: #{command[:limit] || "N/A"}
68
- language: #{command[:language] || "default"}>
69
- }
70
- end
71
-
72
- # Execute the text search command, and return the raw results (in hash
73
- # form).
74
- #
75
- # @example Execute the command.
76
- # text_search.execute
77
- #
78
- # @return [ Hash ] The raw results.
79
- #
80
- # @since 4.0.0
81
- def execute
82
- results
83
- end
84
-
85
- # Set the language of the text search.
86
- #
87
- # @example Set the text search language.
88
- # text_search.language("deutsch")
89
- #
90
- # @param [ String ] value The name of the language.
91
- #
92
- # @return [ TextSearch ] The modified text search.
93
- #
94
- # @since 4.0.0
95
- def language(value)
96
- command[:language] = value
97
- self
98
- end
99
-
100
- # Limits the fields returned by the text search for each document. By
101
- # default, _id is always included.
102
- #
103
- # @example Limit the returned fields.
104
- # text_search.project(name: 1, title: 1)
105
- #
106
- # @param [ Hash ] value The fields to project.
107
- #
108
- # @return [ TextSearch ] The modified text search.
109
- #
110
- # @since 4.0.0
111
- def project(value)
112
- command[:project] = value
113
- self
114
- end
115
-
116
- # Get the raw statistics returned from the text search.
117
- #
118
- # @example Get the stats.
119
- # text_search.stats
120
- #
121
- # @return [ Hash ] The raw statistics.
122
- #
123
- # @since 4.0.0
124
- def stats
125
- results["stats"]
126
- end
127
-
128
- private
129
-
130
- # Apply the options from the criteria to the text search command.
131
- #
132
- # @api private
133
- #
134
- # @example Apply the criteria options, filter and limit only.
135
- # text_search.apply_criteria_options
136
- #
137
- # @return [ nil ] Nothing.
138
- #
139
- # @since 4.0.0
140
- def apply_criteria_options
141
- command[:filter] = criteria.selector
142
- if limit = criteria.options[:limit]
143
- command[:limit] = limit
144
- end
145
- end
146
-
147
- # Get the results of the text search as documents.
148
- #
149
- # @api private
150
- #
151
- # @example Get the results as documents.
152
- # text_search.documents
153
- #
154
- # @return [ Array<Document> ] The documents.
155
- #
156
- # @since 4.0.0
157
- def documents
158
- results["results"].map do |attributes|
159
- Factory.from_db(criteria.klass, attributes["obj"], command[:project])
160
- end
161
- end
162
-
163
- # Get the raw results.
164
- #
165
- # @api private
166
- #
167
- # @example Get the raw results.
168
- # text_search.results
169
- #
170
- # @return [ Hash ] The raw results.
171
- #
172
- # @since 4.0.0
173
- def results
174
- @results ||= session.command(command)
175
- end
176
- end
177
- end
178
- end
@@ -1,141 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid
3
- class Criteria
4
- module Findable
5
-
6
- # Execute the criteria or raise an error if no documents found.
7
- #
8
- # @example Execute or raise
9
- # criteria.execute_or_raise(id)
10
- #
11
- # @param [ Object ] args The arguments passed.
12
- #
13
- # @raise [ Errors::DocumentNotFound ] If nothing returned.
14
- #
15
- # @return [ Document, Array<Document> ] The document(s).
16
- #
17
- # @since 2.0.0
18
- def execute_or_raise(ids, multi)
19
- result = multiple_from_db(ids)
20
- check_for_missing_documents!(result, ids)
21
- multi ? result : result.first
22
- end
23
-
24
- # Find the matchind document(s) in the criteria for the provided ids.
25
- #
26
- # @example Find by an id.
27
- # criteria.find(BSON::ObjectId.new)
28
- #
29
- # @example Find by multiple ids.
30
- # criteria.find([ BSON::ObjectId.new, BSON::ObjectId.new ])
31
- #
32
- # @param [ Array<BSON::ObjectId> ] args The ids to search for.
33
- #
34
- # @return [ Array<Document>, Document ] The matching document(s).
35
- #
36
- # @since 1.0.0
37
- def find(*args)
38
- ids = args.__find_args__
39
- raise_invalid if ids.any?(&:nil?)
40
- p "YOOO"
41
- p ids
42
- for_ids(ids).execute_or_raise(ids, args.multi_arged?)
43
- end
44
-
45
- # Adds a criterion to the +Criteria+ that specifies an id that must be matched.
46
- #
47
- # @example Add a single id criteria.
48
- # criteria.for_ids([ 1 ])
49
- #
50
- # @example Add multiple id criteria.
51
- # criteria.for_ids([ 1, 2 ])
52
- #
53
- # @param [ Array ] ids The array of ids.
54
- #
55
- # @return [ Criteria ] The cloned criteria.
56
- def for_ids(ids)
57
- ids = mongoize_ids(ids)
58
- if ids.size > 1
59
- send(id_finder, { _id: { "$in" => ids }})
60
- else
61
- send(id_finder, { _id: ids.first })
62
- end
63
- end
64
-
65
- # Get the documents from the identity map, and if not found hit the
66
- # database.
67
- #
68
- # @example Get the documents from the map or criteria.
69
- # criteria.multiple_from_map_or_db(ids)
70
- #
71
- # @param [ ids ] The searched ids.
72
- #
73
- # @return [ Array<Document> ] The found documents.
74
- def multiple_from_db(ids)
75
- return entries if embedded?
76
- ids = mongoize_ids(ids)
77
- ids.empty? ? [] : from_database(ids)
78
- end
79
-
80
- private
81
-
82
- # Get the finder used to generate the id query.
83
- #
84
- # @api private
85
- #
86
- # @example Get the id finder.
87
- # criteria.id_finder
88
- #
89
- # @return [ Symbol ] The name of the finder method.
90
- #
91
- # @since 3.1.0
92
- def id_finder
93
- @id_finder ||= extract_id ? :all_of : :where
94
- end
95
-
96
- # Get documents from the database only.
97
- #
98
- # @api private
99
- #
100
- # @example Get documents from the database.
101
- # criteria.from_database(ids)
102
- #
103
- # @param [ Array<Object> ] ids The ids to fetch with.
104
- #
105
- # @return [ Array<Document> ] The matching documents.
106
- #
107
- # @since 3.0.0
108
- def from_database(ids)
109
- (ids.size > 1 ? any_in(id: ids) : where(id: ids.first)).entries
110
- end
111
-
112
- # Convert all the ids to their proper types.
113
- #
114
- # @api private
115
- #
116
- # @example Convert the ids.
117
- # criteria.mongoize_ids(ids)
118
- #
119
- # @param [ Array<Object> ] ids The ids to convert.
120
- #
121
- # @return [ Array<Object> ] The converted ids.
122
- #
123
- # @since 3.0.0
124
- def mongoize_ids(ids)
125
- ids.map{ |id| klass.fields["_id"].mongoize(id) }
126
- end
127
-
128
- # Convenience method of raising an invalid options error.
129
- #
130
- # @example Raise the error.
131
- # criteria.raise_invalid
132
- #
133
- # @raise [ Errors::InvalidOptions ] The error.
134
- #
135
- # @since 2.0.0
136
- def raise_invalid
137
- raise Errors::InvalidFind.new
138
- end
139
- end
140
- end
141
- end
@@ -1,23 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid
3
- module Errors
4
-
5
- # This error is raised when a default session is not defined.
6
- class NoDefaultSession < MongoidError
7
-
8
- # Create the new error with the defined session names.
9
- #
10
- # @example Create the new error.
11
- # NoDefaultSession.new([ :secondary ])
12
- #
13
- # @param [ Array<Symbol> ] keys The defined sessions.
14
- #
15
- # @since 3.0.0
16
- def initialize(keys)
17
- super(
18
- compose_message("no_default_session", { keys: keys.join(", ") })
19
- )
20
- end
21
- end
22
- end
23
- end
@@ -1,22 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid
3
- module Errors
4
-
5
- # This error is raised when attempting to create a new session that does
6
- # not have a named configuration.
7
- class NoSessionConfig < MongoidError
8
-
9
- # Create the new error.
10
- #
11
- # @example Create the error.
12
- # NoSessionConfig.new(:secondary)
13
- #
14
- # @param [ String, Symbol ] name The name of the session.
15
- #
16
- # @since 3.0.0
17
- def initialize(name)
18
- super(compose_message("no_session_config", { name: name }))
19
- end
20
- end
21
- end
22
- end
@@ -1,55 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid
3
- # A Log subscriber to the moped queries
4
- #
5
- # @since 4.0.0
6
- class LogSubscriber < ActiveSupport::LogSubscriber
7
-
8
- # Log the query operation on moped
9
- #
10
- # @since 4.0.0
11
- def query(event)
12
- return unless logger.debug?
13
-
14
- payload = event.payload
15
- runtime = ("%.4fms" % event.duration)
16
- debug(payload[:prefix], payload[:ops], runtime)
17
- end
18
-
19
- def query_cache(event)
20
- return unless logger.debug?
21
-
22
- database, collection, selector = event.payload[:key]
23
- operation = "%-12s database=%s collection=%s selector=%s" % ["QUERY CACHE", database, collection, selector.inspect]
24
- logger.debug operation
25
- end
26
- # Log the provided operations.
27
- #
28
- # @example Delegates the operation to moped so it can log it.
29
- # subscriber.debug("MOPED", {}, 30)
30
- #
31
- # @param [ String ] prefix The prefix for all operations in the log.
32
- # @param [ Array ] ops The operations.
33
- # @param [ String ] runtime The runtime in formatted ms.
34
- #
35
- # @since 4.0.0
36
- def debug(prefix, operations, runtime)
37
- Moped::Loggable.log_operations(prefix, operations, runtime)
38
- end
39
-
40
- # Get the logger.
41
- #
42
- # @example Get the logger.
43
- # subscriber.logger
44
- #
45
- # @return [ Logger ] The logger.
46
- #
47
- # @since 4.0.0
48
- def logger
49
- Moped.logger
50
- end
51
- end
52
- end
53
-
54
- Mongoid::LogSubscriber.attach_to :moped
55
- Mongoid::LogSubscriber.attach_to :mongoid