Class: BufferHash

Inherits:
Hash show all
Defined in:
lib/diakonos/buffer-hash.rb

Overview

A Hash which is iterated in insertion order. Keys are assumed to be paths; these paths are expanded on read and write.

Instance Method Summary collapse

Methods inherited from Hash

#delete_key_path, #get_leaf, #get_node, #set_key_path

Constructor Details

#initializeBufferHash



4
5
6
# File 'lib/diakonos/buffer-hash.rb', line 4

def initialize
  @keys_ = []
end

Instance Method Details

#[](key) ⇒ Object



8
9
10
# File 'lib/diakonos/buffer-hash.rb', line 8

def [] ( key )
  super File.expand_path( key.to_s )
end

#[]=(key, value) ⇒ Object



12
13
14
15
16
17
18
# File 'lib/diakonos/buffer-hash.rb', line 12

def []= ( key, value )
  key = File.expand_path( key.to_s )
  if ! @keys_.include?( key )
    @keys_ << key
  end
  super key, value
end

#clearObject



38
39
40
41
# File 'lib/diakonos/buffer-hash.rb', line 38

def clear
  @keys_ = []
  super
end

#delete(key) ⇒ Object



43
44
45
46
# File 'lib/diakonos/buffer-hash.rb', line 43

def delete( key )
  @keys_.delete key
  super
end

#eachObject



20
21
22
23
24
# File 'lib/diakonos/buffer-hash.rb', line 20

def each
  @keys_.each do |key|
    yield key, self[ key ]
  end
end

#each_keyObject



26
27
28
29
30
# File 'lib/diakonos/buffer-hash.rb', line 26

def each_key
  @keys_.each do |key|
    yield key
  end
end

#each_valueObject



32
33
34
35
36
# File 'lib/diakonos/buffer-hash.rb', line 32

def each_value
  @keys_.each do |key|
    yield self[ key ]
  end
end

#keysObject



48
49
50
# File 'lib/diakonos/buffer-hash.rb', line 48

def keys
  @keys_.dup
end

#lengthObject



56
57
58
# File 'lib/diakonos/buffer-hash.rb', line 56

def length
  @keys_.length
end

#valuesObject



52
53
54
# File 'lib/diakonos/buffer-hash.rb', line 52

def values
  @keys_.map { |key| self[ key ] }
end