Module: Sidekiq::Haron::Storage::RedisConverts

Included in:
Sidekiq::Haron::Storage
Defined in:
lib/sidekiq/haron/redis_converts.rb

Constant Summary collapse

CLASSES_TO_CONVERT =

Введена интерпретация значений nil, true, false в связи с возникающими ошибками:

nil   - 'NilClass'
true  - 'TrueClass'
false - 'FalseClass'
{ NilClass  => {redis_value: 'NilClass',    orig_value: nil},
TrueClass   => {redis_value: 'TrueClass',   orig_value: true},
FalseClass  => {redis_value: 'FalseClass',  orig_value: false} }.freeze

Instance Method Summary collapse

Instance Method Details

#decode_values_from(hash) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/sidekiq/haron/redis_converts.rb', line 22

def decode_values_from hash
  return hash unless hash.is_a?(Hash)

  hash.transform_values do |value|
    key = key_by_redis_value(value)
    value = key.nil? ? value : CLASSES_TO_CONVERT[key][:orig_value]
  end
end

#encode_values_from(array) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/sidekiq/haron/redis_converts.rb', line 14

def encode_values_from array
  return array unless array.is_a?(Array)

  array.map do |value|
    CLASSES_TO_CONVERT.keys.include?(value.class) ? CLASSES_TO_CONVERT[value.class][:redis_value] : value
  end
end