Class: CouchbaseOrm::Types::Hash

Inherits:
ActiveModel::Type::Value
  • Object
show all
Defined in:
lib/couchbase-orm/types/hash.rb

Instance Method Summary collapse

Instance Method Details

#cast(value) ⇒ Object

Raises:

  • (ArgumentError)


6
7
8
9
10
11
12
# File 'lib/couchbase-orm/types/hash.rb', line 6

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.new("Hash: #{value.inspect} (#{value.class}) is not supported for cast")
end

#serialize(value) ⇒ Object

Raises:

  • (ArgumentError)


14
15
16
17
18
19
20
# File 'lib/couchbase-orm/types/hash.rb', line 14

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.new("Hash: #{value.inspect} (#{value.class}) is not supported for serialize")
end