mongo_mapper 0.17.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 +7 -3
- 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/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 +1696 -1689
- data/spec/functional/global_id_spec.rb +21 -0
- data/spec/functional/static_keys_spec.rb +25 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/unit/associations/proxy_spec.rb +1 -1
- data/spec/unit/mongo_mapper_spec.rb +56 -8
- metadata +11 -6
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,7 +30,7 @@ work some more on the project, send an email to Scott Taylor
|
|
|
30
30
|
|
|
31
31
|
MongoMapper is tested against:
|
|
32
32
|
|
|
33
|
-
- MRI 2.4 -
|
|
33
|
+
- MRI 2.4 - 4.0
|
|
34
34
|
- JRuby (Versions with 3.1 compatibility)
|
|
35
35
|
|
|
36
36
|
Additionally, MongoMapper is tested against:
|
|
@@ -38,9 +38,13 @@ Additionally, MongoMapper is tested against:
|
|
|
38
38
|
- Rails 5.0 - 5.2
|
|
39
39
|
- Rails 6.0 - 6.1
|
|
40
40
|
- Rails 7.0 - 7.2
|
|
41
|
-
- Rails 8.0
|
|
41
|
+
- Rails 8.0 - 8.1
|
|
42
42
|
|
|
43
|
-
|
|
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
|
|
44
48
|
|
|
45
49
|
## Contributing & Development
|
|
46
50
|
|
|
@@ -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
|
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