Module: SimpleRedisOrm::Helpers::Serializer

Included in:
CoreCommands, CoreCommands::ClassMethods
Defined in:
lib/simple-redis-orm/helpers/serializer.rb

Instance Method Summary collapse

Instance Method Details

#deserialize_hash_value(hash) ⇒ Object

rubocop:disable Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/simple-redis-orm/helpers/serializer.rb', line 19

def deserialize_hash_value(hash)
  return if hash.nil?

  hash.transform_values do |v|
    next v if v.nil?
    next v unless v.is_a?(String)
    next v unless v.encoding == Encoding::ASCII_8BIT

    v.strip.empty? ? v : MessagePack.unpack(v)
  rescue StandardError => e
    next without_invalid_characters(v) if e.instance_of?(ArgumentError)

    raise e
  end.deep_symbolize_keys
end

#deserialize_value(value) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/simple-redis-orm/helpers/serializer.rb', line 10

def deserialize_value(value)
  return if value.nil?

  return deserialize_hash_value(value) if value.is_a?(Hash)

  MessagePack.unpack(value)
end

#serialize_value(value) ⇒ Object



4
5
6
7
8
# File 'lib/simple-redis-orm/helpers/serializer.rb', line 4

def serialize_value(value)
  return value if value.nil?

  MessagePack.pack(value)
end