mongo_mapper 0.15.5 → 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: ae0bcdb6320444b591dc779d739c553ba371c86e8465c4547c5e35423fe37ade
4
- data.tar.gz: 270341e4efc65ba09578c2ba889c3c2e560610cf6eddfa7889fee19ded37c760
3
+ metadata.gz: eab0f4521b6ddb6f397e27b3b299fbae43def4a8d5f7b406e18aad7da0a54b37
4
+ data.tar.gz: 27b79f11695bbf661b6cc892b151287bb90d2c551b57d40181ecceeabf10a786
5
5
  SHA512:
6
- metadata.gz: 3af02a093ffb4f9b13f48557bd83689c5cdcf35e434c00b152be18ad33e520e9ffbf1b7817b90ac4d363fe6f4452bab2ee66c5c450aca65981cc29ac2e74fe89
7
- data.tar.gz: '09f802a3351959d626e23b4a6fa331ef10749a3b2f259440b527b26a25a23d0f0684c1e2bf0001938357e76fe5664da481ff298b572e665ded6afe0feb5fb286'
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
 
@@ -81,7 +81,7 @@ module MongoMapper
81
81
  # :nocov:
82
82
  if defined?(PhusionPassenger)
83
83
  PhusionPassenger.on_event(:starting_worker_process) do |forked|
84
- connection.connect if forked
84
+ connection.reconnect if forked
85
85
  end
86
86
  end
87
87
  # :nocov:
@@ -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
@@ -9,7 +9,7 @@ module MongoMapper
9
9
  when !persisted?
10
10
  "#{self.class.name}/new"
11
11
  when timestamp = self[:updated_at]
12
- "#{self.class.name}/#{id}-#{timestamp.to_s(:number)}"
12
+ "#{self.class.name}/#{id}-#{timestamp.to_formatted_s(:number)}"
13
13
  else
14
14
  "#{self.class.name}/#{id}"
15
15
  end
@@ -18,4 +18,4 @@ module MongoMapper
18
18
  end
19
19
  end
20
20
  end
21
- end
21
+ end
@@ -49,9 +49,9 @@ module MongoMapper
49
49
  class << self
50
50
  alias_method :__original_#{callback}, :#{callback}
51
51
 
52
- def #{callback}(*args, &block)
52
+ def #{callback}(*args, **options, &block)
53
53
  embedded_callbacks_on if @embedded_callbacks_status.nil?
54
- __original_#{callback}(*args, &block)
54
+ __original_#{callback}(*args, **options, &block)
55
55
  end
56
56
  end
57
57
  CALLBACK
@@ -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
@@ -1,7 +1,15 @@
1
1
  # encoding: UTF-8
2
2
  module MongoMapper
3
3
  module Plugins
4
- include ActiveSupport::DescendantsTracker
4
+ if defined?(ActiveSupport::DescendantsTracker::DescendantsArray)
5
+ DescendantsArray = ::ActiveSupport::DescendantsTracker::DescendantsArray
6
+ else
7
+ DescendantsArray = ::Array
8
+ end
9
+
10
+ def self.direct_descendants_hash
11
+ @direct_descendants_hash ||= Hash.new { |h,k| h[k] = DescendantsArray.new }
12
+ end
5
13
 
6
14
  def plugins
7
15
  @plugins ||= []
@@ -14,9 +22,18 @@ module MongoMapper
14
22
  plugins << mod
15
23
  end
16
24
 
25
+ def direct_descendants
26
+ Plugins.direct_descendants_hash[self]
27
+ end
28
+
17
29
  def included(base = nil)
18
30
  direct_descendants << base if base
19
31
  super
20
32
  end
33
+
34
+ def inherited(subclass)
35
+ direct_descendants << subclass
36
+ super
37
+ end
21
38
  end
22
39
  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.5'
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|