Class: Alt::URI::CachedFields

Inherits:
Object
  • Object
show all
Defined in:
lib/rio/alturi/cached_fields.rb

Constant Summary collapse

DEPENDS =
{
  :uri => [:scheme,:authority,:path,:query,:fragment],
  :authority => [:userinfo,:host,:port]
}
SULLIES =
gen_sullies(DEPENDS)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCachedFields

Returns a new instance of CachedFields.



35
36
37
# File 'lib/rio/alturi/cached_fields.rb', line 35

def initialize
  @store = Hash.new
end

Class Method Details

.flatten_depends_list(depends, list) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# File 'lib/rio/alturi/cached_fields.rb', line 9

def self.flatten_depends_list(depends,list)
  flat = []
  list.each do |sym|
    flat << sym
    if depends[sym]
      flat += flatten_depends_list(depends,depends[sym])
    end
  end
  flat
end

.gen_sullies(depends) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/rio/alturi/cached_fields.rb', line 20

def self.gen_sullies(depends)
  sullies = {}
  depends.each do |key,ary|
    list = flatten_depends_list(depends,ary)
    list.each do |k|
      sullies[k] ||= []
      sullies[k] << key
    end
    sullies[key] ||= []
    sullies[key] += list
  end
  sullies
end

Instance Method Details

#[](key) ⇒ Object



39
40
41
# File 'lib/rio/alturi/cached_fields.rb', line 39

def [](key)
  @store[key]
end

#[]=(key, val) ⇒ Object



54
55
56
57
# File 'lib/rio/alturi/cached_fields.rb', line 54

def []=(key,val)
  clear_key(key)
  @store[key] = val
end

#clear_key(key) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/rio/alturi/cached_fields.rb', line 43

def clear_key(key)
  if klist = SULLIES[key]
    klist.each do |k|
      @store.delete(k)
    end
  end
  @store.delete(key)
end

#has_key?(arg) ⇒ Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/rio/alturi/cached_fields.rb', line 59

def has_key?(arg)
  @store.has_key?(arg)
end

#inspectObject



62
63
64
# File 'lib/rio/alturi/cached_fields.rb', line 62

def inspect
  @store.inspect
end