mongo_mapper 0.15.6 → 0.16.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ab17d58378959cb58a5f2168fe0f9c7740628b4fa470547c708cf9d9740ef668
4
- data.tar.gz: fcba32755feb7d0a439f8d2f0217a2a99092b8cf48317ef6b1f13265874595de
3
+ metadata.gz: eab0f4521b6ddb6f397e27b3b299fbae43def4a8d5f7b406e18aad7da0a54b37
4
+ data.tar.gz: 27b79f11695bbf661b6cc892b151287bb90d2c551b57d40181ecceeabf10a786
5
5
  SHA512:
6
- metadata.gz: 2b0fa4d463705845f6b445c0e4e5d367b931822bb20992704bec606ad133ba4342a426a15785faf237ab91a98b9ff3835c17ee53a520eabe995e129a9c0f3ec6
7
- data.tar.gz: cb57c4f3128a2f3dcb2a80dfd61b3ed473931b600876cf1ab5b00c0a51fe14cf0ba7f503e1779470ef9027957252738aa7e0e7bd9136fe20fbbd31d3c6177eda
6
+ metadata.gz: bd232e1e9ceb0f8c62b17a8d6287aca6d99e97fc22a07b95f423d87e89e9fc0e8a3297800292528051ee3129e96f7f134803f8fd6ad8dd6d191dbf79b8eb452e
7
+ data.tar.gz: cb0e5ce9ced8a690ae5812a576f749a6d82566c92099c8309f13d46e2a25abf5e61869f111b652576c82fee189a0d7ecfce48b8215f0965749122bb99545bb56
data/README.md CHANGED
@@ -30,15 +30,16 @@ 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.0.1
34
- * JRuby (Versions with 1.9 compatibility)
33
+ * MRI 2.4 - 3.2
34
+ * JRuby (Versions with 3.1 compatibility)
35
35
 
36
36
  Additionally, MongoMapper is tested against:
37
37
 
38
38
  * Rails 5.0 - 5.2
39
39
  * Rails 6.0 - 6.1
40
+ * Rails 7.0 - 7.1
40
41
 
41
- Note, if you are using Ruby 3.0+, you'll need Rails 6.
42
+ Note, if you are using Ruby 3.0+, you'll need Rails 6.0+.
42
43
 
43
44
  ## Contributing & Development
44
45
 
@@ -62,7 +63,7 @@ Hit up the Google group: http://groups.google.com/group/mongomapper
62
63
 
63
64
  ## Copyright
64
65
 
65
- Copyright (c) 2009-2021 MongoMapper. See LICENSE for details.
66
+ Copyright (c) 2009-2022 MongoMapper. See LICENSE for details.
66
67
 
67
68
  ## Contributors
68
69
 
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module MongoMapper
4
+ def self.deprecator # :nodoc:
5
+ @deprecator ||= ActiveSupport::Deprecation.new("1.0", "mongo_mapper")
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ module MongoMapper
2
+ module Options
3
+ # @api public
4
+ def filter_attributes=(attributes)
5
+ @filter_attributes = attributes
6
+ end
7
+
8
+ # @api public
9
+ def filter_attributes
10
+ @filter_attributes || []
11
+ end
12
+ end
13
+ end
@@ -7,10 +7,12 @@ module MongoMapper
7
7
  def inspect(include_nil = false)
8
8
  keys = include_nil ? key_names : attributes.keys
9
9
  attributes_as_nice_string = keys.sort.collect do |name|
10
- "#{name}: #{self.send(:"#{name}").inspect}"
10
+ raw_value = self.send(:"#{name}").inspect
11
+ filtered_value = MongoMapper::Utils.filter_param(name, raw_value)
12
+ "#{name}: #{filtered_value}"
11
13
  end.join(", ")
12
14
  "#<#{self.class} #{attributes_as_nice_string}>"
13
15
  end
14
16
  end
15
17
  end
16
- end
18
+ end
@@ -442,7 +442,7 @@ module MongoMapper
442
442
  end
443
443
 
444
444
  def set_parent_document(key, value)
445
- if key.type and value.instance_of?(key.type) && key.embeddable? && value.respond_to?(:_parent_document)
445
+ if key.type and value.kind_of?(key.type) && key.embeddable? && value.respond_to?(:_parent_document)
446
446
  value._parent_document = self
447
447
  end
448
448
  end
@@ -477,7 +477,9 @@ module MongoMapper
477
477
  def initialize_default_values(except = {})
478
478
  @__mm_default_keys.each do |key|
479
479
  if !(except && except.key?(key.name))
480
- internal_write_key key.name, key.default_value, false
480
+ value = key.default_value
481
+ value = key.type ? key.type.to_mongo(value) : value
482
+ internal_write_key key.name, value, false
481
483
  end
482
484
  end
483
485
  end
@@ -6,7 +6,11 @@ module MongoMapper
6
6
  included do
7
7
  include ::ActiveModel::ForbiddenAttributesProtection
8
8
  class << self
9
- deprecate :attr_protected, :attr_accessible
9
+ if ::ActiveSupport.version >= Gem::Version.new("7.1")
10
+ deprecate :attr_protected, :attr_accessible, deprecator: ::MongoMapper.deprecator
11
+ else
12
+ deprecate :attr_protected, :attr_accessible
13
+ end
10
14
  end
11
15
  end
12
16
 
@@ -23,4 +27,4 @@ module MongoMapper
23
27
  end
24
28
  end
25
29
  end
26
- end
30
+ end
@@ -41,6 +41,18 @@ module MongoMapper
41
41
  end
42
42
  end
43
43
 
44
+ if Rails.version >= "6.0"
45
+ initializer "mongo_mapper.filter_attributes=" do |app|
46
+ ActiveSupport.on_load(:mongo_mapper) do
47
+ MongoMapper.filter_attributes += app.config.filter_parameters
48
+ end
49
+ end
50
+ end
51
+
52
+ initializer "mongo_mapper.deprecator" do |app|
53
+ app.deprecators[:mongo_mapper] = MongoMapper.deprecator if app.respond_to?(:deprecators)
54
+ end
55
+
44
56
  # This sets the database configuration and establishes the connection.
45
57
  initializer "mongo_mapper.initialize_database" do |app|
46
58
  config_file = Rails.root.join('config/mongo.yml')
@@ -8,5 +8,17 @@ module MongoMapper
8
8
  safe = {:w => safe} if safe.is_a? Integer
9
9
  safe
10
10
  end
11
+
12
+ def self.filter_param(name, raw_value)
13
+ if ActiveSupport.version >= Gem::Version.new("6.0")
14
+ @filter ||= begin
15
+ require "active_support/parameter_filter"
16
+ ActiveSupport::ParameterFilter.new(MongoMapper.filter_attributes)
17
+ end
18
+ @filter.filter_param(name, raw_value)
19
+ else
20
+ raw_value
21
+ end
22
+ end
11
23
  end
12
24
  end
@@ -1,4 +1,4 @@
1
1
  # encoding: UTF-8
2
2
  module MongoMapper
3
- Version = '0.15.6'
3
+ Version = '0.16.0'
4
4
  end
data/lib/mongo_mapper.rb CHANGED
@@ -4,6 +4,7 @@ require 'active_support'
4
4
  require 'active_support/core_ext'
5
5
  require 'active_model'
6
6
  require 'activemodel-serializers-xml'
7
+ require 'mongo_mapper/deprecator'
7
8
  require "mongo_mapper/railtie" if defined?(Rails)
8
9
 
9
10
  I18n.load_path << File.expand_path('../mongo_mapper/locale/en.yml', __FILE__)
@@ -25,6 +26,7 @@ module MongoMapper
25
26
  autoload :Translation, 'mongo_mapper/translation'
26
27
  autoload :Version, 'mongo_mapper/version'
27
28
  autoload :Utils, 'mongo_mapper/utils'
29
+ autoload :Options, 'mongo_mapper/options'
28
30
 
29
31
  module Middleware
30
32
  autoload :IdentityMap, 'mongo_mapper/middleware/identity_map'
@@ -96,6 +98,7 @@ module MongoMapper
96
98
  end
97
99
 
98
100
  extend Connection
101
+ extend Options
99
102
  end
100
103
 
101
104
  Dir[File.join(File.dirname(__FILE__), 'mongo_mapper', 'extensions', '*.rb')].each do |extension|