Module: Redisabel::HashFunctions

Included in:
KeyHash, KeyOrderedSet
Defined in:
lib/redisabel/hash_functions.rb

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



10
11
12
# File 'lib/redisabel/hash_functions.rb', line 10

def [](key)
  return @data[key]
end

#delete(key) ⇒ Object



23
24
25
26
27
28
# File 'lib/redisabel/hash_functions.rb', line 23

def delete(key)
  if (value = @data.delete(key)) && self.autosave? && !self.id.to_s.empty?
    Database.db.send(self.class.redis_delete_method, self.database_key,
      value)
  end
end

#store(key, value) ⇒ Object Also known as: []=



30
31
32
33
34
35
36
37
# File 'lib/redisabel/hash_functions.rb', line 30

def store(key, value)
  @data.delete(key)
  @data.store(key, value.to_s)
  if self.autosave? && !self.id.to_s.empty?
    Database.db.send(self.class.redis_store_method, self.database_key, key,
      value.to_s)
  end
end

#to_aryObject Also known as: to_a



48
49
50
# File 'lib/redisabel/hash_functions.rb', line 48

def to_ary
  return @data.values.flatten
end

#to_hObject



44
45
46
# File 'lib/redisabel/hash_functions.rb', line 44

def to_h
  return @data.dup
end

#to_hashObject



40
41
42
# File 'lib/redisabel/hash_functions.rb', line 40

def to_hash
  return @data
end

#update_data(*data) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/redisabel/hash_functions.rb', line 14

def update_data(*data)
  data = data.first.is_a?(Hash) ? data.first : {}
  unless data.is_a?(self.class.data_type)
    raise ArgumentError.new("update_data expects a #{self.class.data_type}")
  end

  data.each{ |k, v| self.store(k, v) }
end