mongo_mapper 0.16.0 → 0.18.0
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.
- checksums.yaml +4 -4
- data/README.md +21 -16
- data/lib/mongo_mapper/connection.rb +20 -0
- data/lib/mongo_mapper/document.rb +1 -0
- data/lib/mongo_mapper/plugins/associations/base.rb +3 -9
- data/lib/mongo_mapper/plugins/global_id.rb +8 -0
- data/lib/mongo_mapper/plugins/keys/static.rb +3 -2
- data/lib/mongo_mapper/plugins/serialization.rb +1 -1
- data/lib/mongo_mapper/plugins/stats.rb +5 -2
- data/lib/mongo_mapper/railtie.rb +1 -2
- data/lib/mongo_mapper/version.rb +1 -1
- data/lib/mongo_mapper.rb +5 -0
- data/spec/config/alias.yml +14 -0
- data/spec/config/erb.yml +10 -0
- data/spec/config/simple.yml +11 -0
- data/spec/examples.txt +1683 -1675
- data/spec/functional/global_id_spec.rb +21 -0
- data/spec/functional/static_keys_spec.rb +25 -1
- data/spec/functional/stats_spec.rb +6 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/associations/proxy_spec.rb +1 -1
- data/spec/unit/extensions_spec.rb +6 -1
- data/spec/unit/mongo_mapper_spec.rb +56 -8
- metadata +13 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6ec1c126e62ca7c8293e2d3da8387c17b95e30f638c42bfa8a5b9010b0d110fc
|
|
4
|
+
data.tar.gz: 57010306ab64acc07a5fc30b7e61122162ae3e94aa78a04bbeb4f91aa111a82b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5de8997f8a45d23f14e523863873284c773a640246d50ea73257701d5019ced9b069c6a520551c4479920029ff0754d24a52f3cc357ba08e737b50ffdb2bfe03
|
|
7
|
+
data.tar.gz: 476c8854930a1168abf1deb171caa11dc2f882a7bc0e4c23e683d850d923ac9cb82a384ae2be17ad920a5092422b528fd19acbe36c2870428ed9a068821836c7
|
data/README.md
CHANGED
|
@@ -30,16 +30,21 @@ work some more on the project, send an email to Scott Taylor
|
|
|
30
30
|
|
|
31
31
|
MongoMapper is tested against:
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
- MRI 2.4 - 4.0
|
|
34
|
+
- JRuby (Versions with 3.1 compatibility)
|
|
35
35
|
|
|
36
36
|
Additionally, MongoMapper is tested against:
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
- Rails 5.0 - 5.2
|
|
39
|
+
- Rails 6.0 - 6.1
|
|
40
|
+
- Rails 7.0 - 7.2
|
|
41
|
+
- Rails 8.0 - 8.1
|
|
41
42
|
|
|
42
|
-
|
|
43
|
+
### Notes
|
|
44
|
+
|
|
45
|
+
- if you are using Ruby >= 3.0, you'll need Rails >= 6.0.
|
|
46
|
+
- if you are using Ruby >= 3.4 and Rails <= 7.0, you'll need to add the drb gem to your Gemfile
|
|
47
|
+
- if you are using Ruby >= 3.4 and Rails <= 7.1, you'll need to add the mutex_m gem to your Gemfile
|
|
43
48
|
|
|
44
49
|
## Contributing & Development
|
|
45
50
|
|
|
@@ -47,11 +52,11 @@ Note, if you are using Ruby 3.0+, you'll need Rails 6.0+.
|
|
|
47
52
|
$ bundle install
|
|
48
53
|
$ bundle exec rake
|
|
49
54
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
+
- Fork the project.
|
|
56
|
+
- Make your feature addition or bug fix. All specs should pass.
|
|
57
|
+
- Add specs for your changes. This is important so that it doesn't break in a future version.
|
|
58
|
+
- 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 a maintainer can ignore it when your pull request is merged.
|
|
59
|
+
- Send a pull request. Bonus points for topic branches.
|
|
55
60
|
|
|
56
61
|
## How to release
|
|
57
62
|
|
|
@@ -63,15 +68,15 @@ Hit up the Google group: http://groups.google.com/group/mongomapper
|
|
|
63
68
|
|
|
64
69
|
## Copyright
|
|
65
70
|
|
|
66
|
-
Copyright (c) 2009-
|
|
71
|
+
Copyright (c) 2009-2023 MongoMapper. See LICENSE for details.
|
|
67
72
|
|
|
68
73
|
## Contributors
|
|
69
74
|
|
|
70
75
|
MongoMapper/Plucky is:
|
|
71
76
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
77
|
+
- John Nunemaker
|
|
78
|
+
- Chris Heald
|
|
79
|
+
- Scott Taylor
|
|
75
80
|
|
|
76
81
|
But all open source projects are a team effort and could not happen without
|
|
77
|
-
everyone who has contributed.
|
|
82
|
+
everyone who has contributed. See `CONTRIBUTORS` for the full list. Thank you!
|
|
@@ -50,6 +50,11 @@ module MongoMapper
|
|
|
50
50
|
config[environment.to_s]
|
|
51
51
|
end
|
|
52
52
|
|
|
53
|
+
MONGOMAPPER_WRAPPING_LIBRARY = {
|
|
54
|
+
name: 'MongoMapper',
|
|
55
|
+
version: Version,
|
|
56
|
+
}.freeze
|
|
57
|
+
|
|
53
58
|
def connect(environment, options={})
|
|
54
59
|
raise 'Set config before connecting. MongoMapper.config = {...}' if config.blank?
|
|
55
60
|
env = config_for_environment(environment).dup
|
|
@@ -68,6 +73,8 @@ module MongoMapper
|
|
|
68
73
|
end
|
|
69
74
|
|
|
70
75
|
options[:read] = options[:read].to_sym if options[:read].is_a? String
|
|
76
|
+
options[:wrapping_libraries] = [MONGOMAPPER_WRAPPING_LIBRARY]
|
|
77
|
+
|
|
71
78
|
MongoMapper.connection = Mongo::Client.new(addresses_or_uri, options)
|
|
72
79
|
end
|
|
73
80
|
|
|
@@ -77,6 +84,19 @@ module MongoMapper
|
|
|
77
84
|
connect(environment, options)
|
|
78
85
|
end
|
|
79
86
|
|
|
87
|
+
def setup_with_config_file(path, environment, options={})
|
|
88
|
+
source = ERB.new(File.read(path)).result
|
|
89
|
+
|
|
90
|
+
yaml_major, yaml_minor, _ = Gem::Version.new(YAML::VERSION).segments
|
|
91
|
+
config = if yaml_major >= 4 || (yaml_major == 3 && yaml_minor >= 1)
|
|
92
|
+
YAML.safe_load(source, aliases: true)
|
|
93
|
+
else
|
|
94
|
+
YAML.safe_load(source, [], [], true)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
MongoMapper.setup(config, environment, options)
|
|
98
|
+
end
|
|
99
|
+
|
|
80
100
|
def handle_passenger_forking
|
|
81
101
|
# :nocov:
|
|
82
102
|
if defined?(PhusionPassenger)
|
|
@@ -3,7 +3,7 @@ module MongoMapper
|
|
|
3
3
|
module Plugins
|
|
4
4
|
module Associations
|
|
5
5
|
class Base
|
|
6
|
-
attr_reader :name, :options, :query_options
|
|
6
|
+
attr_reader :name, :options, :query_options, :foreign_key, :ivar
|
|
7
7
|
|
|
8
8
|
# Options that should not be considered MongoDB query options/criteria
|
|
9
9
|
AssociationOptions = [:as, :class, :class_name, :dependent, :extend, :foreign_key, :in, :from, :polymorphic, :autosave, :touch, :counter_cache, :ordered]
|
|
@@ -13,6 +13,8 @@ module MongoMapper
|
|
|
13
13
|
options.symbolize_keys!
|
|
14
14
|
options[:extend] = modularized_extensions(extension, options[:extend])
|
|
15
15
|
separate_options_and_conditions
|
|
16
|
+
@foreign_key = (options[:foreign_key] || "#{name}_id").freeze
|
|
17
|
+
@ivar = "@_#{name}".freeze
|
|
16
18
|
end
|
|
17
19
|
|
|
18
20
|
def class_name
|
|
@@ -63,14 +65,6 @@ module MongoMapper
|
|
|
63
65
|
@options[:as] || self.name
|
|
64
66
|
end
|
|
65
67
|
|
|
66
|
-
def foreign_key
|
|
67
|
-
@options[:foreign_key] || "#{name}_id"
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
def ivar
|
|
71
|
-
@ivar ||= "@_#{name}"
|
|
72
|
-
end
|
|
73
|
-
|
|
74
68
|
# :nocov:
|
|
75
69
|
def proxy_class
|
|
76
70
|
raise NotImplementedError
|
|
@@ -35,11 +35,12 @@ module MongoMapper
|
|
|
35
35
|
def load_from_database(attrs, with_cast = false)
|
|
36
36
|
return super if !self.class.static_keys || !attrs.respond_to?(:each)
|
|
37
37
|
|
|
38
|
-
|
|
38
|
+
embedded_keys = self.class.embedded_associations.map(&:name).map(&:to_s)
|
|
39
|
+
attrs = attrs.select { |key, _| self.class.key?(key) || key.in?(embedded_keys) }
|
|
39
40
|
|
|
40
41
|
super(attrs, with_cast)
|
|
41
42
|
end
|
|
42
43
|
end
|
|
43
44
|
end
|
|
44
45
|
end
|
|
45
|
-
end
|
|
46
|
+
end
|
|
@@ -18,7 +18,7 @@ module MongoMapper
|
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
def serializable_hash(options = nil)
|
|
21
|
-
options
|
|
21
|
+
options = options ? options.dup : {}
|
|
22
22
|
|
|
23
23
|
options[:only] = Array.wrap(options[:only]).map { |k| k.to_s }
|
|
24
24
|
options[:except] = Array.wrap(options[:except]).map { |k| k.to_s }
|
|
@@ -5,8 +5,11 @@ module MongoMapper
|
|
|
5
5
|
module Stats
|
|
6
6
|
extend ActiveSupport::Concern
|
|
7
7
|
module ClassMethods
|
|
8
|
-
def stats
|
|
9
|
-
|
|
8
|
+
def stats(scale: nil)
|
|
9
|
+
query = { :collstats => collection.name }
|
|
10
|
+
query[:scale] = scale if scale
|
|
11
|
+
|
|
12
|
+
stats = database.command(query).documents[0]
|
|
10
13
|
Struct.new(*stats.keys.collect { |key| key.underscore.to_sym }).new(*stats.values)
|
|
11
14
|
rescue
|
|
12
15
|
nil
|
data/lib/mongo_mapper/railtie.rb
CHANGED
|
@@ -57,8 +57,7 @@ module MongoMapper
|
|
|
57
57
|
initializer "mongo_mapper.initialize_database" do |app|
|
|
58
58
|
config_file = Rails.root.join('config/mongo.yml')
|
|
59
59
|
if config_file.file?
|
|
60
|
-
|
|
61
|
-
MongoMapper.setup(config, Rails.env, :logger => Rails.logger)
|
|
60
|
+
MongoMapper.setup_with_config_file(config_file, Rails.env, :logger => Rails.logger)
|
|
62
61
|
end
|
|
63
62
|
end
|
|
64
63
|
end
|
data/lib/mongo_mapper/version.rb
CHANGED
data/lib/mongo_mapper.rb
CHANGED
|
@@ -6,6 +6,10 @@ require 'active_model'
|
|
|
6
6
|
require 'activemodel-serializers-xml'
|
|
7
7
|
require 'mongo_mapper/deprecator'
|
|
8
8
|
require "mongo_mapper/railtie" if defined?(Rails)
|
|
9
|
+
begin
|
|
10
|
+
require 'globalid'
|
|
11
|
+
rescue LoadError
|
|
12
|
+
end
|
|
9
13
|
|
|
10
14
|
I18n.load_path << File.expand_path('../mongo_mapper/locale/en.yml', __FILE__)
|
|
11
15
|
|
|
@@ -70,6 +74,7 @@ module MongoMapper
|
|
|
70
74
|
autoload :Userstamps, 'mongo_mapper/plugins/userstamps'
|
|
71
75
|
autoload :Validations, 'mongo_mapper/plugins/validations'
|
|
72
76
|
autoload :Touch, 'mongo_mapper/plugins/touch'
|
|
77
|
+
autoload :GlobalID, 'mongo_mapper/plugins/global_id'
|
|
73
78
|
|
|
74
79
|
module Associations
|
|
75
80
|
autoload :Base, 'mongo_mapper/plugins/associations/base'
|
data/spec/config/erb.yml
ADDED