class Fluent::Plugin::NetflowParser::Vash
Public Class Methods
new(constructor = {})
click to toggle source
Calls superclass method
# File lib/fluent/plugin/vash.rb, line 6 def initialize(constructor = {}) @register ||= {} if constructor.is_a?(Hash) super() merge(constructor) else super(constructor) end end
Public Instance Methods
[](key)
click to toggle source
# File lib/fluent/plugin/vash.rb, line 19 def [](key) sterilize(key) clear(key) if expired?(key) regular_reader(key) end
Also aliased as: regular_reader
[]=(key, *args)
click to toggle source
# File lib/fluent/plugin/vash.rb, line 25 def []=(key, *args) if args.length == 2 value, ttl = args[1], args[0] elsif args.length == 1 value, ttl = args[0], 60 else raise ArgumentError, "Wrong number of arguments, expected 2 or 3, received: #{args.length+1}\n"+ "Example Usage: volatile_hash[:key]=value OR volatile_hash[:key, ttl]=value" end sterilize(key) ttl(key, ttl) regular_writer(key, value) end
Also aliased as: regular_writer
cleanup!()
click to toggle source
# File lib/fluent/plugin/vash.rb, line 44 def cleanup! now = Time.now.to_i @register.map {|k,v| clear(k) if v < now} end
clear(key)
click to toggle source
# File lib/fluent/plugin/vash.rb, line 49 def clear(key) sterilize(key) @register.delete key self.delete key end
merge(hsh)
click to toggle source
# File lib/fluent/plugin/vash.rb, line 39 def merge(hsh) hsh.map {|key,value| self[sterile(key)] = hsh[key]} self end
Private Instance Methods
expired?(key)
click to toggle source
# File lib/fluent/plugin/vash.rb, line 57 def expired?(key) Time.now.to_i > @register[key].to_i end
sterile(key)
click to toggle source
# File lib/fluent/plugin/vash.rb, line 65 def sterile(key) String === key ? key.chomp('!').chomp('=') : key.to_s.chomp('!').chomp('=').to_sym end
sterilize(key)
click to toggle source
# File lib/fluent/plugin/vash.rb, line 69 def sterilize(key) key = sterile(key) end
ttl(key, secs=60)
click to toggle source
# File lib/fluent/plugin/vash.rb, line 61 def ttl(key, secs=60) @register[key] = Time.now.to_i + secs.to_i end