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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eab0f4521b6ddb6f397e27b3b299fbae43def4a8d5f7b406e18aad7da0a54b37
4
- data.tar.gz: 27b79f11695bbf661b6cc892b151287bb90d2c551b57d40181ecceeabf10a786
3
+ metadata.gz: 6ec1c126e62ca7c8293e2d3da8387c17b95e30f638c42bfa8a5b9010b0d110fc
4
+ data.tar.gz: 57010306ab64acc07a5fc30b7e61122162ae3e94aa78a04bbeb4f91aa111a82b
5
5
  SHA512:
6
- metadata.gz: bd232e1e9ceb0f8c62b17a8d6287aca6d99e97fc22a07b95f423d87e89e9fc0e8a3297800292528051ee3129e96f7f134803f8fd6ad8dd6d191dbf79b8eb452e
7
- data.tar.gz: cb0e5ce9ced8a690ae5812a576f749a6d82566c92099c8309f13d46e2a25abf5e61869f111b652576c82fee189a0d7ecfce48b8215f0965749122bb99545bb56
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
- * MRI 2.4 - 3.2
34
- * JRuby (Versions with 3.1 compatibility)
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
- * Rails 5.0 - 5.2
39
- * Rails 6.0 - 6.1
40
- * Rails 7.0 - 7.1
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
- 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
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
- * Fork the project.
51
- * Make your feature addition or bug fix. All specs should pass.
52
- * Add specs for your changes. This is important so that it doesn't break in a future version.
53
- * 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.
54
- * Send a pull request. Bonus points for topic branches.
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-2022 MongoMapper. See LICENSE for details.
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
- * John Nunemaker
73
- * Chris Heald
74
- * Scott Taylor
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. See `CONTRIBUTORS` for the full list. Thank you!
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)
@@ -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
@@ -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
- stats = database.command(:collstats => collection.name).documents[0]
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
@@ -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.16.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