forked from acaprojects/couchbase-orm
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Giallombardo Nathan
committed
May 28, 2024
1 parent
5b31677
commit 1b2e41a
Showing
4 changed files
with
53 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module CouchbaseOrm | ||
module Types | ||
class Hash < ActiveModel::Type::Value | ||
def cast(value) | ||
return nil if value.nil? | ||
return value if value.is_a?(ActiveSupport::HashWithIndifferentAccess) | ||
return value.with_indifferent_access if value.is_a?(::Hash) | ||
|
||
raise ArgumentError, "Hash: #{value.inspect} (#{value.class}) is not supported for cast" | ||
end | ||
|
||
def serialize(value) | ||
return nil if value.nil? | ||
return value.as_json if value.is_a?(ActiveSupport::HashWithIndifferentAccess) | ||
return value.with_indifferent_access.as_json if value.is_a?(::Hash) | ||
|
||
raise ArgumentError, "Hash: #{value.inspect} (#{value.class}) is not supported for serialize" | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters