mongo_mapper_ign 0.7.7 → 0.7.8

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.
Files changed (50) hide show
  1. data/LICENSE +20 -20
  2. data/README.rdoc +34 -34
  3. data/bin/mmconsole +60 -60
  4. data/lib/mongo_mapper.rb +123 -123
  5. data/lib/mongo_mapper/document.rb +292 -292
  6. data/lib/mongo_mapper/embedded_document.rb +71 -71
  7. data/lib/mongo_mapper/plugins.rb +36 -36
  8. data/lib/mongo_mapper/plugins/associations.rb +115 -115
  9. data/lib/mongo_mapper/plugins/associations/base.rb +124 -124
  10. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +31 -31
  11. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +26 -26
  12. data/lib/mongo_mapper/plugins/associations/collection.rb +21 -21
  13. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +39 -39
  14. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +160 -144
  15. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +29 -29
  16. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +130 -130
  17. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +32 -32
  18. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +24 -24
  19. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +14 -14
  20. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +42 -42
  21. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +70 -70
  22. data/lib/mongo_mapper/plugins/associations/proxy.rb +125 -125
  23. data/lib/mongo_mapper/plugins/callbacks.rb +241 -241
  24. data/lib/mongo_mapper/plugins/clone.rb +13 -13
  25. data/lib/mongo_mapper/plugins/descendants.rb +16 -16
  26. data/lib/mongo_mapper/plugins/dirty.rb +119 -119
  27. data/lib/mongo_mapper/plugins/equality.rb +23 -23
  28. data/lib/mongo_mapper/plugins/identity_map.rb +123 -123
  29. data/lib/mongo_mapper/plugins/inspect.rb +14 -14
  30. data/lib/mongo_mapper/plugins/keys.rb +322 -322
  31. data/lib/mongo_mapper/plugins/keys/key.rb +53 -53
  32. data/lib/mongo_mapper/plugins/logger.rb +17 -17
  33. data/lib/mongo_mapper/plugins/modifiers.rb +111 -111
  34. data/lib/mongo_mapper/plugins/pagination.rb +24 -24
  35. data/lib/mongo_mapper/plugins/pagination/proxy.rb +72 -72
  36. data/lib/mongo_mapper/plugins/persistence.rb +96 -96
  37. data/lib/mongo_mapper/plugins/protected.rb +46 -46
  38. data/lib/mongo_mapper/plugins/rails.rb +57 -57
  39. data/lib/mongo_mapper/plugins/serialization.rb +92 -92
  40. data/lib/mongo_mapper/plugins/serialization/array.rb +56 -56
  41. data/lib/mongo_mapper/plugins/serialization/xml_serializer.rb +239 -239
  42. data/lib/mongo_mapper/plugins/timestamps.rb +21 -21
  43. data/lib/mongo_mapper/plugins/userstamps.rb +14 -14
  44. data/lib/mongo_mapper/plugins/validations.rb +46 -46
  45. data/lib/mongo_mapper/query.rb +28 -28
  46. data/lib/mongo_mapper/support.rb +197 -197
  47. data/lib/mongo_mapper/support/descendant_appends.rb +46 -46
  48. data/lib/mongo_mapper/support/find.rb +77 -77
  49. data/lib/mongo_mapper/version.rb +3 -3
  50. metadata +4 -25
data/LICENSE CHANGED
@@ -1,20 +1,20 @@
1
- Copyright (c) 2009 John Nunemaker
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2009 John Nunemaker
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,35 +1,35 @@
1
- = MongoMapper
2
-
3
- A Ruby Object Mapper for Mongo. mongo_mapper_ign gem includes support for xml serialization
4
-
5
- Releases are tagged on github and released on gemcutter. Master is pushed to whenever I add a patch or a new feature, but I do not release a new gem version each time I push.
6
-
7
- == Note on Patches/Pull Requests
8
-
9
- * Fork the project.
10
- * Make your feature addition or bug fix.
11
- * Add tests for it. This is important so I don't break it in a future version unintentionally.
12
- * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
13
- * Send me a pull request. Bonus points for topic branches.
14
-
15
- == Install
16
-
17
- $ gem install mongo_mapper_ign
18
-
19
- == Config Rails environment.rb
20
-
21
- config.gem "mongo_mapper_ign", :lib => "mongo_mapper"
22
-
23
- == Problems or Questions?
24
-
25
- Hit up the google group.
26
- http://groups.google.com/group/mongomapper
27
-
28
- To see if the problem you are having is a verified issue, you can see the MM pivotal tracker project:
29
- http://www.pivotaltracker.com/projects/33576
30
-
31
- There is no need to request to join the Pivotal Tracker project as I am only granting access to a select few (easier to keep things organized). If you have a problem, please use the mailing list. If I confirm it to be a bug, I am happy to add it to PT. Thanks!
32
-
33
- == Copyright
34
-
1
+ = MongoMapper
2
+
3
+ A Ruby Object Mapper for Mongo. mongo_mapper_ign gem includes support for xml serialization
4
+
5
+ Releases are tagged on github and released on gemcutter. Master is pushed to whenever I add a patch or a new feature, but I do not release a new gem version each time I push.
6
+
7
+ == Note on Patches/Pull Requests
8
+
9
+ * Fork the project.
10
+ * Make your feature addition or bug fix.
11
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
12
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Install
16
+
17
+ $ gem install mongo_mapper_ign
18
+
19
+ == Config Rails environment.rb
20
+
21
+ config.gem "mongo_mapper_ign", :lib => "mongo_mapper"
22
+
23
+ == Problems or Questions?
24
+
25
+ Hit up the google group.
26
+ http://groups.google.com/group/mongomapper
27
+
28
+ To see if the problem you are having is a verified issue, you can see the MM pivotal tracker project:
29
+ http://www.pivotaltracker.com/projects/33576
30
+
31
+ There is no need to request to join the Pivotal Tracker project as I am only granting access to a select few (easier to keep things organized). If you have a problem, please use the mailing list. If I confirm it to be a bug, I am happy to add it to PT. Thanks!
32
+
33
+ == Copyright
34
+
35
35
  Copyright (c) 2009 John Nunemaker. See LICENSE for details.
@@ -1,60 +1,60 @@
1
- #!/usr/bin/env ruby
2
- $:.unshift(File.dirname(__FILE__) + '/../lib')
3
-
4
- begin
5
- require 'mongo_mapper'
6
- require 'irb'
7
- rescue LoadError
8
- require 'rubygems'
9
- retry
10
- end
11
-
12
- IRB.setup(nil)
13
- irb = IRB::Irb.new
14
-
15
- IRB.conf[:MAIN_CONTEXT] = irb.context
16
-
17
- irb.context.evaluate("require 'irb/completion'", 0)
18
- irb.context.evaluate(%@
19
- include MongoMapper
20
-
21
- MongoMapper.database = "mmtest"
22
- $db = MongoMapper.database
23
-
24
- @, 0)
25
-
26
- puts %@
27
- Welcome to the MongoMapper Console!
28
-
29
- Example 1:
30
- things = $db.collection("things")
31
- things.insert("name" => "Raw Thing")
32
- things.insert("name" => "Another Thing", "date" => Time.now)
33
-
34
- cursor = things.find("name" => "Raw Thing")
35
- puts cursor.next_object.inspect
36
-
37
- Example 2:
38
- class Thing
39
- include MongoMapper::Document
40
- key :name, String, :required => true
41
- key :date, Time
42
- end
43
-
44
- thing = Thing.new
45
- thing.name = "My thing"
46
- thing.date = Time.now
47
- thing.save
48
-
49
- all_things = Thing.all
50
- puts all_things.map { |object| object.name }.inspect
51
- @
52
-
53
- trap("SIGINT") do
54
- irb.signal_handle
55
- end
56
-
57
- catch(:IRB_EXIT) do
58
- irb.eval_input
59
- end
60
-
1
+ #!/usr/bin/env ruby
2
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
3
+
4
+ begin
5
+ require 'mongo_mapper'
6
+ require 'irb'
7
+ rescue LoadError
8
+ require 'rubygems'
9
+ retry
10
+ end
11
+
12
+ IRB.setup(nil)
13
+ irb = IRB::Irb.new
14
+
15
+ IRB.conf[:MAIN_CONTEXT] = irb.context
16
+
17
+ irb.context.evaluate("require 'irb/completion'", 0)
18
+ irb.context.evaluate(%@
19
+ include MongoMapper
20
+
21
+ MongoMapper.database = "mmtest"
22
+ $db = MongoMapper.database
23
+
24
+ @, 0)
25
+
26
+ puts %@
27
+ Welcome to the MongoMapper Console!
28
+
29
+ Example 1:
30
+ things = $db.collection("things")
31
+ things.insert("name" => "Raw Thing")
32
+ things.insert("name" => "Another Thing", "date" => Time.now)
33
+
34
+ cursor = things.find("name" => "Raw Thing")
35
+ puts cursor.next_object.inspect
36
+
37
+ Example 2:
38
+ class Thing
39
+ include MongoMapper::Document
40
+ key :name, String, :required => true
41
+ key :date, Time
42
+ end
43
+
44
+ thing = Thing.new
45
+ thing.name = "My thing"
46
+ thing.date = Time.now
47
+ thing.save
48
+
49
+ all_things = Thing.all
50
+ puts all_things.map { |object| object.name }.inspect
51
+ @
52
+
53
+ trap("SIGINT") do
54
+ irb.signal_handle
55
+ end
56
+
57
+ catch(:IRB_EXIT) do
58
+ irb.eval_input
59
+ end
60
+
@@ -1,123 +1,123 @@
1
- # encoding: UTF-8
2
- # Make sure you have the correct versions of the gems (see gemspec) in your load path.
3
- require 'set'
4
- require 'uri'
5
- require 'plucky'
6
- require 'validatable'
7
- require 'active_support/all'
8
-
9
- module MongoMapper
10
- # generic MM error
11
- class MongoMapperError < StandardError; end
12
-
13
- # raised when key expected to exist but not found
14
- class KeyNotFound < MongoMapperError; end
15
-
16
- # raised when document expected but not found
17
- class DocumentNotFound < MongoMapperError; end
18
-
19
- # raised when trying to connect using uri with incorrect scheme
20
- class InvalidScheme < MongoMapperError; end
21
-
22
- # raised when document not valid and using !
23
- class DocumentNotValid < MongoMapperError
24
- def initialize(document)
25
- super("Validation failed: #{document.errors.full_messages.join(", ")}")
26
- end
27
- end
28
-
29
- # @api public
30
- def self.connection
31
- @@connection ||= Mongo::Connection.new
32
- end
33
-
34
- # @api public
35
- def self.connection=(new_connection)
36
- @@connection = new_connection
37
- end
38
-
39
- # @api public
40
- def self.logger
41
- connection.logger
42
- end
43
-
44
- # @api public
45
- def self.database=(name)
46
- @@database = nil
47
- @@database_name = name
48
- end
49
-
50
- # @api public
51
- def self.database
52
- if @@database_name.blank?
53
- raise 'You forgot to set the default database name: MongoMapper.database = "foobar"'
54
- end
55
-
56
- @@database ||= MongoMapper.connection.db(@@database_name)
57
- end
58
-
59
- # @api public
60
- def self.slave_connections
61
- @@slave_connections ||= []
62
- end
63
-
64
- # @api public
65
- def self.slave_connections=(slaves = [])
66
- @@slave_connections = slaves
67
- end
68
-
69
- def self.config=(hash)
70
- @@config = hash
71
- end
72
-
73
- def self.config
74
- raise 'Set config before connecting. MongoMapper.config = {...}' unless defined?(@@config)
75
- @@config
76
- end
77
-
78
- # @api private
79
- def self.config_for_environment(environment)
80
- env = config[environment]
81
- return env if env['uri'].blank?
82
-
83
- uri = URI.parse(env['uri'])
84
- raise InvalidScheme.new('must be mongodb') unless uri.scheme == 'mongodb'
85
- {
86
- 'host' => uri.host,
87
- 'port' => uri.port,
88
- 'database' => uri.path.gsub(/^\//, ''),
89
- 'username' => uri.user,
90
- 'password' => uri.password,
91
- }
92
- end
93
-
94
- def self.connect(environment, options={})
95
- raise 'Set config before connecting. MongoMapper.config = {...}' if config.blank?
96
- env = config_for_environment(environment)
97
- MongoMapper.connection = Mongo::Connection.new(env['host'], env['port'], options)
98
- MongoMapper.database = env['database']
99
- MongoMapper.database.authenticate(env['username'], env['password']) if env['username'] && env['password']
100
- end
101
-
102
- def self.setup(config, environment, options={})
103
- handle_passenger_forking
104
- self.config = config
105
- connect(environment, options)
106
- end
107
-
108
- def self.handle_passenger_forking
109
- if defined?(PhusionPassenger)
110
- PhusionPassenger.on_event(:starting_worker_process) do |forked|
111
- connection.connect_to_master if forked
112
- end
113
- end
114
- end
115
-
116
- autoload :Query, 'mongo_mapper/query'
117
- autoload :Document, 'mongo_mapper/document'
118
- autoload :EmbeddedDocument, 'mongo_mapper/embedded_document'
119
- autoload :Version, 'mongo_mapper/version'
120
- end
121
-
122
- require 'mongo_mapper/support'
123
- require 'mongo_mapper/plugins'
1
+ # encoding: UTF-8
2
+ # Make sure you have the correct versions of the gems (see gemspec) in your load path.
3
+ require 'set'
4
+ require 'uri'
5
+ require 'plucky'
6
+ require 'validatable'
7
+ require 'active_support/all'
8
+
9
+ module MongoMapper
10
+ # generic MM error
11
+ class MongoMapperError < StandardError; end
12
+
13
+ # raised when key expected to exist but not found
14
+ class KeyNotFound < MongoMapperError; end
15
+
16
+ # raised when document expected but not found
17
+ class DocumentNotFound < MongoMapperError; end
18
+
19
+ # raised when trying to connect using uri with incorrect scheme
20
+ class InvalidScheme < MongoMapperError; end
21
+
22
+ # raised when document not valid and using !
23
+ class DocumentNotValid < MongoMapperError
24
+ def initialize(document)
25
+ super("Validation failed: #{document.errors.full_messages.join(", ")}")
26
+ end
27
+ end
28
+
29
+ # @api public
30
+ def self.connection
31
+ @@connection ||= Mongo::Connection.new
32
+ end
33
+
34
+ # @api public
35
+ def self.connection=(new_connection)
36
+ @@connection = new_connection
37
+ end
38
+
39
+ # @api public
40
+ def self.logger
41
+ connection.logger
42
+ end
43
+
44
+ # @api public
45
+ def self.database=(name)
46
+ @@database = nil
47
+ @@database_name = name
48
+ end
49
+
50
+ # @api public
51
+ def self.database
52
+ if @@database_name.blank?
53
+ raise 'You forgot to set the default database name: MongoMapper.database = "foobar"'
54
+ end
55
+
56
+ @@database ||= MongoMapper.connection.db(@@database_name)
57
+ end
58
+
59
+ # @api public
60
+ def self.slave_connections
61
+ @@slave_connections ||= []
62
+ end
63
+
64
+ # @api public
65
+ def self.slave_connections=(slaves = [])
66
+ @@slave_connections = slaves
67
+ end
68
+
69
+ def self.config=(hash)
70
+ @@config = hash
71
+ end
72
+
73
+ def self.config
74
+ raise 'Set config before connecting. MongoMapper.config = {...}' unless defined?(@@config)
75
+ @@config
76
+ end
77
+
78
+ # @api private
79
+ def self.config_for_environment(environment)
80
+ env = config[environment]
81
+ return env if env['uri'].blank?
82
+
83
+ uri = URI.parse(env['uri'])
84
+ raise InvalidScheme.new('must be mongodb') unless uri.scheme == 'mongodb'
85
+ {
86
+ 'host' => uri.host,
87
+ 'port' => uri.port,
88
+ 'database' => uri.path.gsub(/^\//, ''),
89
+ 'username' => uri.user,
90
+ 'password' => uri.password,
91
+ }
92
+ end
93
+
94
+ def self.connect(environment, options={})
95
+ raise 'Set config before connecting. MongoMapper.config = {...}' if config.blank?
96
+ env = config_for_environment(environment)
97
+ MongoMapper.connection = Mongo::Connection.new(env['host'], env['port'], options)
98
+ MongoMapper.database = env['database']
99
+ MongoMapper.database.authenticate(env['username'], env['password']) if env['username'] && env['password']
100
+ end
101
+
102
+ def self.setup(config, environment, options={})
103
+ handle_passenger_forking
104
+ self.config = config
105
+ connect(environment, options)
106
+ end
107
+
108
+ def self.handle_passenger_forking
109
+ if defined?(PhusionPassenger)
110
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
111
+ connection.connect_to_master if forked
112
+ end
113
+ end
114
+ end
115
+
116
+ autoload :Query, 'mongo_mapper/query'
117
+ autoload :Document, 'mongo_mapper/document'
118
+ autoload :EmbeddedDocument, 'mongo_mapper/embedded_document'
119
+ autoload :Version, 'mongo_mapper/version'
120
+ end
121
+
122
+ require 'mongo_mapper/support'
123
+ require 'mongo_mapper/plugins'