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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74ec9f278a24ea6d1a430b798204b50f2e69e96f5d01d3cd564a4a582b3683c8
4
- data.tar.gz: d803b9283fcef845d9d841d2d93dba96084bdeb55c316b0f9350e304e2fbe809
3
+ metadata.gz: 6ec1c126e62ca7c8293e2d3da8387c17b95e30f638c42bfa8a5b9010b0d110fc
4
+ data.tar.gz: 57010306ab64acc07a5fc30b7e61122162ae3e94aa78a04bbeb4f91aa111a82b
5
5
  SHA512:
6
- metadata.gz: e58932d6d99c84dd711aaac5162fa4ac7e6fd518e187f9c544e2498fb215aa3ab21f6f70e27abfddb312a594c0ec115a217eede15772202a8e6c24b6b51dc051
7
- data.tar.gz: 23f13767289d092fb1aad74fb4dc18d92a573b42fd4bf938b426ea15fcfdc317de252c6100a3687a11e7edce855bfa13a10e3e956e2e2eb182314208182b0351
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 - 3.2
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
- Note, if you are using Ruby 3.0+, you'll need Rails 6.0+.
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)
@@ -40,6 +40,7 @@ module MongoMapper
40
40
  include Plugins::IdentityMap
41
41
  include Plugins::CounterCache
42
42
  include Plugins::Shardable
43
+ include Plugins::GlobalID if defined?(::GlobalID)
43
44
 
44
45
  included do
45
46
  extend Plugins
@@ -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
@@ -0,0 +1,8 @@
1
+ # encoding: UTF-8
2
+ module MongoMapper
3
+ module Plugins
4
+ module GlobalID
5
+ include ::GlobalID::Identification
6
+ end
7
+ end
8
+ end
@@ -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
- attrs = attrs.select { |key, _| self.class.key?(key) }
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
@@ -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
- config = YAML.load(ERB.new(config_file.read).result)
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
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module MongoMapper
3
- Version = '0.17.0'
3
+ Version = '0.18.0'
4
4
  end
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'
@@ -0,0 +1,14 @@
1
+ default: &default
2
+ host: 127.0.0.1:21017
3
+
4
+ production:
5
+ <<: *default
6
+ database: production
7
+
8
+ development:
9
+ <<: *default
10
+ database: development
11
+
12
+ test:
13
+ <<: *default
14
+ database: test
@@ -0,0 +1,10 @@
1
+ production:
2
+ uri: <%= ENV["MONGODB_URI"] %>
3
+
4
+ development:
5
+ host: 127.0.0.1:21017
6
+ database: development
7
+
8
+ test:
9
+ host: 127.0.0.1:21017
10
+ database: test
@@ -0,0 +1,11 @@
1
+ production:
2
+ host: 127.0.0.1:21017
3
+ database: production
4
+
5
+ development:
6
+ host: 127.0.0.1:21017
7
+ database: development
8
+
9
+ test:
10
+ host: 127.0.0.1:21017
11
+ database: test