-
Notifications
You must be signed in to change notification settings - Fork 1.4k
MONGOID-5408 .evolve should support wrapper class #5448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
483e8ad
7284c78
a61a30e
a81a998
92f38b3
f757a27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ def to_pipeline | |
|
||
# Get the store name and store value. If the value is of type range, | ||
# we need may need to change the store_name as well as the store_value, | ||
# therefore, we cannot just use the evole method. | ||
# therefore, we cannot just use the evolve method. | ||
# | ||
# @param [ String ] name The name of the field. | ||
# @param [ Object ] serializer The optional serializer for the field. | ||
|
@@ -150,6 +150,8 @@ def evolve_multi(specs) | |
# | ||
# @return [ Object ] The serialized object. | ||
def evolve(serializer, value) | ||
return value.raw_value if value.is_a?(Mongoid::RawValue) | ||
johnnyshields marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey @johnnyshields -- I hate to keep drawing this PR out, but I wanted to ask if there was a specific reason for using a guard here, rather than adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed it. Good catch. |
||
|
||
case value | ||
when Hash | ||
evolve_hash(serializer, value) | ||
|
@@ -228,7 +230,7 @@ def evolve_hash(serializer, value) | |
# | ||
# @api private | ||
# | ||
# @param [ String ] key The to store the range for. | ||
# @param [ String ] key The key at which to store the range. | ||
# @param [ Object ] serializer The optional serializer for the field. | ||
# @param [ Range ] value The Range to serialize. | ||
# | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
# Wrapper class used when a value cannot be casted in evolve method. | ||
module Mongoid | ||
def RawValue(*args) | ||
johnnyshields marked this conversation as resolved.
Show resolved
Hide resolved
johnnyshields marked this conversation as resolved.
Show resolved
Hide resolved
|
||
RawValue.new(*args) | ||
end | ||
|
||
class RawValue | ||
|
||
attr_reader :raw_value | ||
|
||
def initialize(raw_value) | ||
@raw_value = raw_value | ||
end | ||
|
||
# Returns a string containing a human-readable representation of | ||
# the object, including the inspection of the underlying value. | ||
# | ||
# @return [ String ] The object inspection. | ||
def inspect | ||
"RawValue: #{raw_value.inspect}" | ||
end | ||
end | ||
end |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I copy-pasted the "Embedded Documents" section to be after "Fields" w/out edits to it, as I felt it made more sense order-wise vis-a-vis additions to Fields section in this PR.