File tree Expand file tree Collapse file tree 5 files changed +27
-3
lines changed Expand file tree Collapse file tree 5 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,12 @@ please consult GitHub releases for detailed release notes and JIRA for
18
18
the complete list of issues fixed in each release, including bug fixes.
19
19
20
20
21
+ ``for_js`` method is deprecated
22
+ -------------------------------
23
+
24
+ The ``for_js`` method is deprecated and will be removed in Mongoid 10.0.
25
+
26
+
21
27
Deprecated options removed
22
28
--------------------------
23
29
Original file line number Diff line number Diff line change @@ -78,6 +78,8 @@ def count(options = {}, &block)
78
78
if valid_for_count_documents?
79
79
view . count_documents ( options )
80
80
else
81
+ # TODO: Remove this when we remove the deprecated for_js API.
82
+ # https://jira.mongodb.org/browse/MONGOID-5681
81
83
view . count ( options )
82
84
end
83
85
end
@@ -1049,6 +1051,9 @@ def process_raw_docs(raw_docs, limit)
1049
1051
#
1050
1052
# @return [ true | false ] whether or not the current context
1051
1053
# excludes a `$where` operator.
1054
+ #
1055
+ # TODO: Remove this method when we remove the deprecated for_js API.
1056
+ # https://jira.mongodb.org/browse/MONGOID-5681
1052
1057
def valid_for_count_documents? ( hash = view . filter )
1053
1058
# Note that `view.filter` is a BSON::Document, and all keys in a
1054
1059
# BSON::Document are strings; we don't need to worry about symbol
Original file line number Diff line number Diff line change @@ -41,6 +41,8 @@ class Criteria
41
41
include Clients ::Sessions
42
42
include Options
43
43
44
+ Mongoid . deprecate ( self , :for_js )
45
+
44
46
# Static array used to check with method missing - we only need to ever
45
47
# instantiate once.
46
48
CHECK = [ ]
@@ -439,6 +441,8 @@ def without_options
439
441
# @param [ Hash ] scope The scope for the code.
440
442
#
441
443
# @return [ Criteria ] The criteria.
444
+ #
445
+ # @deprecated
442
446
def for_js ( javascript , scope = { } )
443
447
code = if scope . empty?
444
448
# CodeWithScope is not supported for $where as of MongoDB 4.4
Original file line number Diff line number Diff line change @@ -6,10 +6,13 @@ module Mongoid
6
6
# Utility class for logging deprecation warnings.
7
7
class Deprecation < ::ActiveSupport ::Deprecation
8
8
9
- @gem_name = 'Mongoid'
9
+ def initialize
10
+ # Per change policy, deprecations will be removed in the next major version.
11
+ deprecation_horizon = "#{ Mongoid ::VERSION . split ( '.' ) . first . to_i + 1 } .0" . freeze
12
+ gem_name = 'Mongoid'
13
+ super ( deprecation_horizon , gem_name )
14
+ end
10
15
11
- # Per change policy, deprecations will be removed in the next major version.
12
- @deprecation_horizon = "#{ Mongoid ::VERSION . split ( '.' ) . first . to_i + 1 } .0" . freeze
13
16
14
17
# Overrides default ActiveSupport::Deprecation behavior
15
18
# to use Mongoid's logger.
Original file line number Diff line number Diff line change @@ -2977,6 +2977,12 @@ def self.ages; self; end
2977
2977
Band . create! ( name : "Depeche Mode" )
2978
2978
end
2979
2979
2980
+ it 'is deprecated' do
2981
+ expect ( Mongoid . logger ) . to receive ( :warn ) . with ( /for_js is deprecated/ ) . and_call_original
2982
+
2983
+ Band . for_js ( "this.name == 'Depeche Mode'" )
2984
+ end
2985
+
2980
2986
context "when the code has no scope" do
2981
2987
2982
2988
let ( :criteria ) do
You can’t perform that action at this time.
0 commit comments