module Redisabel::HashFunctions

Public Instance Methods

[](key) click to toggle source
# File lib/redisabel/hash_functions.rb, line 10
def [](key)
  return @data[key]
end
[]=(key, value)
Alias for: store
delete(key) click to toggle source
# 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) click to toggle source
# 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
Also aliased as: []=
to_a()
Alias for: to_ary
to_ary() click to toggle source
# File lib/redisabel/hash_functions.rb, line 48
def to_ary
  return @data.values.flatten
end
Also aliased as: to_a
to_h() click to toggle source
# File lib/redisabel/hash_functions.rb, line 44
def to_h
  return @data.dup
end
to_hash() click to toggle source
# File lib/redisabel/hash_functions.rb, line 40
def to_hash
  return @data
end
update_data(*data) click to toggle source
# 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

Protected Instance Methods

key_valid?(key) click to toggle source
# File lib/redisabel/hash_functions.rb, line 5
def key_valid?(key)
  return key.is_a?(Numeric)
end