lib/masterview/mtime_tracking_hash.rb in masterview-0.3.2 vs lib/masterview/mtime_tracking_hash.rb in masterview-0.3.3

- old
+ new

@@ -1,39 +1,48 @@ module MasterView # this hash is designed to track modified times of its values - # this behaviour is only supported through using []= and store + # this behaviour is only supported through using []= and store # mechanisms and thus default semantics have been excluded - # other update methods such as merge! have been excluded from + # other update methods such as merge! have been excluded from # this implementation and will raise errors class MTimeTrackingHash < Hash # MTimeTrackingHash does not support defaults and thus does # not take default object or block def initialize super @mtimes = {} end - + def []=(key, value) update_mtime(key) super end def store(key, value) update_mtime(key) super end + def delete(key) + delete_mtime(key) + super + end + # returns the Time object for this key def mtime(key) @mtimes[key] end private def update_mtime(key) @mtimes[key] = Time.now + end + + def delete_mtime(key) + @mtimes.delete(key) end def default=(obj); raise "Not implemented"; end def merge!(obj,&block); raise "Not implemented"; end def reject!(obj,&block); raise "Not implemented"; end