Skip to content

Commit 0944a04

Browse files
committed
More changes
1 parent ae79a78 commit 0944a04

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

lib/mongoid/config.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ module Config
6868
# existing method.
6969
option :scope_overwrite_exception, default: false
7070

71+
# Indicates whether or not to raise an error when attempting
72+
# to assign an incompatible type to a field.
73+
option :strict_type_assignment, default: false
74+
7175
# Use ActiveSupport's time zone in time operations instead of the
7276
# Ruby default time zone.
7377
option :use_activesupport_time_zone, default: true

lib/mongoid/criteria/queryable/selector.rb

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,16 +150,20 @@ def evolve_multi(specs)
150150
#
151151
# @return [ Object ] The serialized object.
152152
def evolve(serializer, value)
153-
case value
154-
when Hash
155-
evolve_hash(serializer, value)
156-
when Array
157-
evolve_array(serializer, value)
158-
when Range
159-
value.__evolve_range__(serializer: serializer)
160-
else
161-
(serializer || value.class).evolve(value)
162-
end
153+
_value = case value
154+
when Hash
155+
evolve_hash(serializer, value)
156+
when Array
157+
evolve_array(serializer, value)
158+
when Range
159+
value.__evolve_range__(serializer: serializer)
160+
when Mongoid::UncastableValue
161+
value
162+
else
163+
(serializer || value.class).evolve(value)
164+
end
165+
_value = _value.raw_value if _value.is_a?(Mongoid::UncastableValue)
166+
_value
163167
end
164168

165169
# Evolve a single key selection with array values.

lib/mongoid/stringified_symbol.rb

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ class << self
1717
#
1818
# @api private
1919
def demongoize(object)
20-
if object.nil?
21-
object
22-
else
23-
object.to_s.to_sym
24-
end
20+
return nil if object.nil?
21+
return object.to_s.to_sym if object.respond_to?(:to_s)
22+
Mongoid::UncastableValue.new(object, 'String')
2523
end
2624

2725
# Turn the object from the ruby type we deal with to a Mongo friendly
@@ -36,11 +34,9 @@ def demongoize(object)
3634
#
3735
# @api private
3836
def mongoize(object)
39-
if object.nil?
40-
object
41-
else
42-
object.to_s
43-
end
37+
return nil if object.nil?
38+
return object.to_s if object.respond_to?(:to_s)
39+
Mongoid::UncastableValue.new(object, 'String')
4440
end
4541

4642
# @api private

0 commit comments

Comments
 (0)