Class: Spider::FlashHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/spiderfw/controller/session/flash_hash.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFlashHash



7
8
9
10
11
12
13
# File 'lib/spiderfw/controller/session/flash_hash.rb', line 7

def initialize
    super
    @sub_flashes = {}
    @parent_flash = nil
    @parent_flash_key = nil
    reset
end

Instance Attribute Details

#accessedObject (readonly)

Returns the value of attribute accessed



5
6
7
# File 'lib/spiderfw/controller/session/flash_hash.rb', line 5

def accessed
  @accessed
end

#active(key) ⇒ Object (readonly)

Returns the value of attribute active



5
6
7
8
9
10
# File 'lib/spiderfw/controller/session/flash_hash.rb', line 5

def active(key)
    @active[key] = true
    if (@parent_flash)
        @parent_flash.active(@parent_flash_key)
    end
end

#parent_flashObject

Returns the value of attribute parent_flash



4
5
6
# File 'lib/spiderfw/controller/session/flash_hash.rb', line 4

def parent_flash
  @parent_flash
end

#parent_flash_keyObject

Returns the value of attribute parent_flash_key



4
5
6
# File 'lib/spiderfw/controller/session/flash_hash.rb', line 4

def parent_flash_key
  @parent_flash_key
end

Instance Method Details

#[](key) ⇒ Object



21
22
23
24
# File 'lib/spiderfw/controller/session/flash_hash.rb', line 21

def [](key)
    @accessed[key] = true
    super
end

#[]=(key, val) ⇒ Object



26
27
28
29
30
31
32
33
34
# File 'lib/spiderfw/controller/session/flash_hash.rb', line 26

def []=(key, val)
    super
    active(key)
    if (val.is_a?(FlashHash))
        val.parent_flash = self
        val.parent_flash_key = key
        @sub_flashes[key] = val
    end
end

#delete(key) ⇒ Object



43
44
45
46
# File 'lib/spiderfw/controller/session/flash_hash.rb', line 43

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

#purgeObject



48
49
50
51
# File 'lib/spiderfw/controller/session/flash_hash.rb', line 48

def purge
    self.delete_if{ |k, v| @accessed[k] && !@active[k] }
    @sub_flashes.each{ |k, f| f.purge }
end

#resetObject



15
16
17
18
19
# File 'lib/spiderfw/controller/session/flash_hash.rb', line 15

def reset
    @active = {}
    @accessed = {}
    @sub_flashes.each{ |k, f| f.reset }
end