Module: RedisHash::Deletions

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/redis_hash/concerns/deletions.rb

Instance Method Summary collapse

Instance Method Details

#clearObject



12
13
14
# File 'lib/redis_hash/concerns/deletions.rb', line 12

def clear
  del(redis_key) and {}
end

#delete(field) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/redis_hash/concerns/deletions.rb', line 16

def delete(field)
  run_callbacks(:deletion) do
    value = self[field]
    result = hdel(redis_key, field)
    (result == 0 && block_given?) ? yield(field) : value
  end
end

#shiftObject



24
25
26
27
28
29
# File 'lib/redis_hash/concerns/deletions.rb', line 24

def shift
  return to_default if empty?

  field = keys.first
  [ field, delete(field) ]
end