Sha256: 2d3d31ac691e1237535c6c3ac6aaa750996b39688c32bb4b07c2490491e83bbe

Contents?: true

Size: 1.03 KB

Versions: 9

Compression:

Stored size: 1.03 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

    # returns the Time object for this key
    def mtime(key)
      @mtimes[key]
    end

    private

    def update_mtime(key)
      @mtimes[key] = Time.now
    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

9 entries across 9 versions & 1 rubygems

Version Path
masterview-0.2.0 lib/masterview/mtime_tracking_hash.rb
masterview-0.2.1 lib/masterview/mtime_tracking_hash.rb
masterview-0.2.4 lib/masterview/mtime_tracking_hash.rb
masterview-0.2.5 lib/masterview/mtime_tracking_hash.rb
masterview-0.3.0 lib/masterview/mtime_tracking_hash.rb
masterview-0.3.1 lib/masterview/mtime_tracking_hash.rb
masterview-0.2.2 lib/masterview/mtime_tracking_hash.rb
masterview-0.3.2 lib/masterview/mtime_tracking_hash.rb
masterview-0.2.3 lib/masterview/mtime_tracking_hash.rb