Sha256: 70a73e71ffa0af95c1f152abc5d21f49b40524c9cffc78e66484818caf6bcc3c

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

module MasterView

  # this hash is designed to track modified times of its values
  # 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
  # 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
    def replace(obj); raise "Not implemented"; end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
masterview-0.3.3 lib/masterview/mtime_tracking_hash.rb
masterview-0.3.4 lib/masterview/mtime_tracking_hash.rb