class Redis::TrackedHash

Public Instance Methods

added() click to toggle source
# File lib/redis/tracked_hash.rb, line 31
def added
  self.keys - original.keys
end
changed() click to toggle source
# File lib/redis/tracked_hash.rb, line 21
def changed
  changes = keys.select do |key|
    self[key] != original[key]
  end
end
deleted() click to toggle source
# File lib/redis/tracked_hash.rb, line 27
def deleted
  original.keys - self.keys
end
dup() click to toggle source
Calls superclass method
# File lib/redis/tracked_hash.rb, line 40
def dup
  dupe = super
  # duplicate a little deeper
  # otherwise, object references will make it appear a value hasn't changed when it has
  self.keys.each do |k|
    dupe[k] = self[k].dup rescue self[k]
  end
  dupe
end
merge!(other_hash)
Alias for: update
original() click to toggle source
# File lib/redis/tracked_hash.rb, line 4
def original
  @original ||= self.dup
end
Also aliased as: track, track!
populate(other_hash) click to toggle source
# File lib/redis/tracked_hash.rb, line 35
def populate(other_hash)
  update(other_hash)
  retrack!
end
retrack() click to toggle source
# File lib/redis/tracked_hash.rb, line 15
def retrack
  untrack!
  track!
end
Also aliased as: retrack!
retrack!()
Alias for: retrack
track()
Alias for: original
track!()
Alias for: original
untrack() click to toggle source
# File lib/redis/tracked_hash.rb, line 10
def untrack
  @original = nil
end
Also aliased as: untrack!
untrack!()
Alias for: untrack
update(other_hash) click to toggle source
Calls superclass method
# File lib/redis/tracked_hash.rb, line 50
def update(other_hash)
  if other_hash.kind_of?(TrackedHash)
    other_original = other_hash.original
    other_hash.instance_variable_set('@original',original)
    other_changed = other_hash.changed
    other_hash.deleted.each { |key| delete(key) }
    other_hash.instance_variable_set('@original',other_original)
    updates = Hash[ other_changed.map { |k| [k, other_hash[k]] } ]
    super( updates )
  else
    super
  end
end
Also aliased as: merge!