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,71 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid
3
-
4
- # This module is responsible for taking update selectors and switching out
5
- # the indexes for the $ positional operator where appropriate.
6
- #
7
- # @since 4.0.0
8
- module Positional
9
-
10
- # Takes the provided selector and atomic operations and replaces the
11
- # indexes of the embedded documents with the positional operator when
12
- # needed.
13
- #
14
- # @note The only time we can accurately know when to use the positional
15
- # operator is at the exact time we are going to persist something. So
16
- # we can tell by the selector that we are sending if it is actually
17
- # possible to use the positional operator at all. For example, if the
18
- # selector is: { "_id" => 1 }, then we could not use the positional
19
- # operator for updating embedded documents since there would never be a
20
- # match - we base whether we can based on the number of levels deep the
21
- # selector goes, and if the id values are not nil.
22
- #
23
- # @example Process the operations.
24
- # positionally(
25
- # { "_id" => 1, "addresses._id" => 2 },
26
- # { "$set" => { "addresses.0.street" => "hobrecht" }}
27
- # )
28
- #
29
- # @param [ Hash ] selector The selector.
30
- # @param [ Hash ] operations The update operations.
31
- # @param [ Hash ] processed The processed update operations.
32
- #
33
- # @return [ Hash ] The new operations.
34
- #
35
- # @since 3.1.0
36
- def positionally(selector, operations, processed = {})
37
- if selector.size == 1 || selector.values.any? { |val| val.nil? }
38
- return operations
39
- end
40
- keys = selector.keys.map{ |m| m.sub('._id','') } - ['_id']
41
- keys = keys.sort_by { |s| s.length*-1 }
42
- process_operations(keys, operations, processed)
43
- end
44
-
45
- private
46
-
47
- def process_operations(keys, operations, processed)
48
- operations.each_pair do |operation, update|
49
- processed[operation] = process_updates(keys, update)
50
- end
51
- processed
52
- end
53
-
54
- def process_updates(keys, update, updates = {})
55
- update.each_pair do |position, value|
56
- updates[replace_index(keys, position)] = value
57
- end
58
- updates
59
- end
60
-
61
- def replace_index(keys, position)
62
- # replace to $ only if that key is on the selector
63
- keys.each do |kk|
64
- if position =~ /^#{kk}\.\d+\.(.*)/
65
- return "#{kk}.$.#{$1}"
66
- end
67
- end
68
- position
69
- end
70
- end
71
- end
@@ -1,125 +0,0 @@
1
- # encoding: utf-8
2
- require "mongoid/sessions/factory"
3
- require "mongoid/sessions/validators"
4
- require "mongoid/sessions/storage_options"
5
- require "mongoid/sessions/thread_options"
6
- require "mongoid/sessions/options"
7
-
8
- module Mongoid
9
- module Sessions
10
- extend ActiveSupport::Concern
11
- include StorageOptions
12
- include ThreadOptions
13
- include Options
14
-
15
- class << self
16
- # Clear all sessions from the current thread.
17
- #
18
- # @example Clear all sessions.
19
- # Mongoid::Sessions.clear
20
- #
21
- # @return [ Array ] The empty sessions.
22
- #
23
- # @since 3.0.0
24
- def clear
25
- Threaded.sessions.clear
26
- end
27
-
28
- # Get the default session.
29
- #
30
- # @example Get the default session.
31
- # Mongoid::Sessions.default
32
- #
33
- # @return [ Moped::Session ] The default session.
34
- #
35
- # @since 3.0.0
36
- def default
37
- Threaded.sessions[:default] ||= Sessions::Factory.default
38
- end
39
-
40
- # Disconnect all active sessions.
41
- #
42
- # @example Disconnect all active sessions.
43
- # Mongoid::Sessions.disconnect
44
- #
45
- # @return [ true ] True.
46
- #
47
- # @since 3.1.0
48
- def disconnect
49
- Threaded.sessions.values.each do |session|
50
- session.disconnect
51
- end
52
- end
53
-
54
- # Get a session with the provided name.
55
- #
56
- # @example Get a session with the name.
57
- # Mongoid::Sessions.with_name(:replica)
58
- #
59
- # @param [ Symbol ] name The name of the session.
60
- #
61
- # @return [ Moped::Session ] The named session.
62
- #
63
- # @since 3.0.0
64
- def with_name(name)
65
- Threaded.sessions[name.to_sym] ||= Sessions::Factory.create(name)
66
- end
67
- end
68
-
69
- # Get the collection for this model from the session. Will check for an
70
- # overridden collection name from the store_in macro or the collection
71
- # with a pluralized model name.
72
- #
73
- # @example Get the model's collection.
74
- # Model.collection
75
- #
76
- # @return [ Moped::Collection ] The collection.
77
- #
78
- # @since 3.0.0
79
- def collection
80
- mongo_session[collection_name]
81
- end
82
-
83
- def mongo_session
84
- super || self.class.mongo_session
85
- end
86
-
87
- def collection_name
88
- super || self.class.collection_name
89
- end
90
-
91
- module ClassMethods
92
-
93
- # Get the session for this model. This is determined in the following order:
94
- #
95
- # 1. Any custom configuration provided by the 'store_in' macro.
96
- # 2. The 'default' session as provided in the mongoid.yml
97
- #
98
- # @example Get the session.
99
- # Model.mongo_session
100
- #
101
- # @return [ Moped::Session ] The default moped session.
102
- #
103
- # @since 3.0.0
104
- def mongo_session
105
- session = Sessions.with_name(session_name)
106
- session.use(database_name)
107
- self.persistence_options ? session.with(self.persistence_options) : session
108
- end
109
-
110
- # Get the collection for this model from the session. Will check for an
111
- # overridden collection name from the store_in macro or the collection
112
- # with a pluralized model name.
113
- #
114
- # @example Get the model's collection.
115
- # Model.collection
116
- #
117
- # @return [ Moped::Collection ] The collection.
118
- #
119
- # @since 3.0.0
120
- def collection
121
- mongo_session[collection_name]
122
- end
123
- end
124
- end
125
- end
@@ -1,131 +0,0 @@
1
- # encoding: utf-8
2
- require "mongoid/sessions/mongo_uri"
3
-
4
- module Mongoid
5
- module Sessions
6
- module Factory
7
- extend self
8
-
9
- # Create a new session given the named configuration. If no name is
10
- # provided, return a new session with the default configuration. If a
11
- # name is provided for which no configuration exists, an error will be
12
- # raised.
13
- #
14
- # @example Create the session.
15
- # Factory.create(:secondary)
16
- #
17
- # @param [ String, Symbol ] name The named session configuration.
18
- #
19
- # @raise [ Errors::NoSessionConfig ] If no config could be found.
20
- #
21
- # @return [ Moped::Session ] The new session.
22
- #
23
- # @since 3.0.0
24
- def create(name = nil)
25
- return default unless name
26
- config = Mongoid.sessions[name]
27
- raise Errors::NoSessionConfig.new(name) unless config
28
- create_session(config)
29
- end
30
-
31
- # Get the default session.
32
- #
33
- # @example Get the default session.
34
- # Factory.default
35
- #
36
- # @raise [ Errors::NoSessionConfig ] If no default configuration is
37
- # found.
38
- #
39
- # @return [ Moped::Session ] The default session.
40
- #
41
- # @since 3.0.0
42
- def default
43
- create_session(Mongoid.sessions[:default])
44
- end
45
-
46
- private
47
-
48
- # Create the session for the provided config.
49
- #
50
- # @api private
51
- #
52
- # @example Create the session.
53
- # Factory.create_session(config)
54
- #
55
- # @param [ Hash ] configuration The session config.
56
- #
57
- # @return [ Moped::Session ] The session.
58
- #
59
- # @since 3.0.0
60
- def create_session(configuration)
61
- raise Errors::NoSessionsConfig.new unless configuration
62
- config, options = parse(configuration)
63
- configuration.merge!(config) if configuration.delete(:uri)
64
-
65
- options[:instrumenter] = ActiveSupport::Notifications
66
- session = Moped::Session.new(config[:hosts], options)
67
- session.use(config[:database])
68
- if authenticated?(config)
69
- session.login(config[:username], config[:password])
70
- end
71
- session
72
- end
73
-
74
- # Are we authenticated with this session config?
75
- #
76
- # @api private
77
- #
78
- # @example Is this session authenticated?
79
- # Factory.authenticated?(config)
80
- #
81
- # @param [ Hash ] config The session config.
82
- #
83
- # @return [ true, false ] If we are authenticated.
84
- #
85
- # @since 3.0.0
86
- def authenticated?(config)
87
- config.has_key?(:username) && config.has_key?(:password)
88
- end
89
-
90
- # Parse the configuration. If a uri is provided we need to extract the
91
- # elements of it, otherwise the options are left alone.
92
- #
93
- # @api private
94
- #
95
- # @example Parse the config.
96
- # Factory.parse(config)
97
- #
98
- # @param [ Hash ] config The configuration.
99
- #
100
- # @return [ Array<Hash> ] The configuration, parsed.
101
- #
102
- # @since 3.0.0
103
- def parse(config)
104
- options = config[:options].try(:dup) || {}
105
- parsed = if config.has_key?(:uri)
106
- MongoUri.new(config[:uri]).to_hash
107
- else
108
- inject_ports(config)
109
- end
110
- [ parsed, options.symbolize_keys ]
111
- end
112
-
113
- # Will inject the default port of 27017 if not supplied.
114
- #
115
- # @example Inject default ports.
116
- # factory.inject_ports(config)
117
- #
118
- # @param [ Hash ] config The session configuration.
119
- #
120
- # @return [ Hash ] The altered configuration.
121
- #
122
- # @since 3.1.0
123
- def inject_ports(config)
124
- config["hosts"] = config["hosts"].map do |host|
125
- host =~ /:/ ? host : "#{host}:27017"
126
- end
127
- config
128
- end
129
- end
130
- end
131
- end
@@ -1,93 +0,0 @@
1
- # encoding: utf-8
2
- module Mongoid
3
- module Sessions
4
- class MongoUri
5
-
6
- SCHEME = /(mongodb:\/\/)/
7
- USER = /([-.\w:]+)/
8
- PASS = /([^@,]+)/
9
- NODES = /((([-.\w]+)(?::(\w+))?,?)+)/
10
- DATABASE = /(?:\/([-\w]+))?/
11
-
12
- URI = /#{SCHEME}(#{USER}:#{PASS}@)?#{NODES}#{DATABASE}/
13
-
14
- attr_reader :match
15
-
16
- # Get the database provided in the URI.
17
- #
18
- # @example Get the database.
19
- # uri.database
20
- #
21
- # @return [ String ] The database.
22
- #
23
- # @since 3.0.0
24
- def database
25
- @database ||= match[9]
26
- end
27
-
28
- # Get the hosts provided in the URI.
29
- #
30
- # @example Get the hosts.
31
- # uri.hosts
32
- #
33
- # @return [ Array<String> ] The hosts.
34
- #
35
- # @since 3.0.0
36
- def hosts
37
- @hosts ||= match[5].split(",")
38
- end
39
-
40
- # Create the new uri from the provided string.
41
- #
42
- # @example Create the new uri.
43
- # MongoUri.new(uri)
44
- #
45
- # @param [ String ] string The uri string.
46
- #
47
- # @since 3.0.0
48
- def initialize(string)
49
- @match = string.match(URI)
50
- end
51
-
52
- # Get the password provided in the URI.
53
- #
54
- # @example Get the password.
55
- # uri.password
56
- #
57
- # @return [ String ] The password.
58
- #
59
- # @since 3.0.0
60
- def password
61
- @password ||= match[4]
62
- end
63
-
64
- # Get the uri as a Mongoid friendly configuration hash.
65
- #
66
- # @example Get the uri as a hash.
67
- # uri.to_hash
68
- #
69
- # @return [ Hash ] The uri as options.
70
- #
71
- # @since 3.0.0
72
- def to_hash
73
- config = { database: database, hosts: hosts }
74
- if username && password
75
- config.merge!(username: username, password: password)
76
- end
77
- config
78
- end
79
-
80
- # Get the username provided in the URI.
81
- #
82
- # @example Get the username.
83
- # uri.username
84
- #
85
- # @return [ String ] The username.
86
- #
87
- # @since 3.0.0
88
- def username
89
- @username ||= match[3]
90
- end
91
- end
92
- end
93
- end
@@ -1,2 +0,0 @@
1
- # encoding: utf-8
2
- require "mongoid/sessions/validators/storage"
@@ -1,23 +0,0 @@
1
- module Mongoid
2
-
3
- class QueryCounter
4
- attr_reader :events
5
-
6
- def initialize
7
- @events = []
8
- end
9
-
10
- def instrument
11
- subscriber = ActiveSupport::Notifications.subscribe('query.moped') do |*args|
12
- @events << ActiveSupport::Notifications::Event.new(*args)
13
- end
14
- yield
15
- ensure
16
- ActiveSupport::Notifications.unsubscribe(subscriber)
17
- end
18
-
19
- def inspect
20
- @events.map { |e| e.payload[:ops].map(&:log_inspect) }.join("\n")
21
- end
22
- end
23
- end