Sha256: 10e4fc9fcfb840e785f56b5f6ee1ab13f4a9c88a4af4e2fb6a4614293cbbb3d6

Contents?: true

Size: 1.25 KB

Versions: 61

Compression:

Stored size: 1.25 KB

Contents

module Spider
    
    class FlashHash < Hash
        attr_accessor :parent_flash, :parent_flash_key
        attr_reader :accessed, :active
        
        def initialize
            super
            @sub_flashes = {}
            @parent_flash = nil
            @parent_flash_key = nil
            reset
        end
        
        def reset
            @active = {}
            @accessed = {}
            @sub_flashes.each{ |k, f| f.reset }
        end
        
        def [](key)
            @accessed[key] = true
            super
        end
        
        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
        
        def active(key)
            @active[key] = true
            if (@parent_flash)
                @parent_flash.active(@parent_flash_key)
            end
        end
        
        def delete(key)
            super
            @sub_flashes.delete(key)
        end
        
        def purge
            self.delete_if{ |k, v| @accessed[k] && !@active[k] }
            @sub_flashes.each{ |k, f| f.purge }
        end
        
    end
    
    
end

Version data entries

61 entries across 61 versions & 1 rubygems

Version Path
spiderfw-1.0.1 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-1.0.0 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.39 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.38 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.37 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.35 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.34 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.33 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.32 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.31 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.30 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.29 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.28 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.27 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.26 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.26.pre1 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.25 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.24 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.23 lib/spiderfw/controller/session/flash_hash.rb
spiderfw-0.6.22 lib/spiderfw/controller/session/flash_hash.rb