Class: Vash

Inherits:
Hash
  • Object
show all
Defined in:
lib/logstash/codecs/netflow/util.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(constructor = {}) ⇒ Vash



213
214
215
216
217
218
219
220
221
# File 'lib/logstash/codecs/netflow/util.rb', line 213

def initialize(constructor = {})
  @register ||= {}
  if constructor.is_a?(Hash)
    super()
    merge(constructor)
  else
    super(constructor)
  end
end

Instance Method Details

#[](key) ⇒ Object



226
227
228
229
230
# File 'lib/logstash/codecs/netflow/util.rb', line 226

def [](key)
  sterilize(key)
  clear(key) if expired?(key)
  regular_reader(key)
end

#[]=(key, *args) ⇒ Object



232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/logstash/codecs/netflow/util.rb', line 232

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

#cleanup!Object



251
252
253
254
# File 'lib/logstash/codecs/netflow/util.rb', line 251

def cleanup!
  now = Time.now.to_i
  @register.map {|k,v| clear(k) if v < now}
end

#clear(key) ⇒ Object



256
257
258
259
260
# File 'lib/logstash/codecs/netflow/util.rb', line 256

def clear(key)
  sterilize(key)
  @register.delete key
  self.delete key
end

#merge(hsh) ⇒ Object



246
247
248
249
# File 'lib/logstash/codecs/netflow/util.rb', line 246

def merge(hsh)
  hsh.map {|key,value| self[sterile(key)] = hsh[key]}
  self
end

#regular_readerObject



224
# File 'lib/logstash/codecs/netflow/util.rb', line 224

alias_method :regular_reader, :[]

#regular_writerObject



223
# File 'lib/logstash/codecs/netflow/util.rb', line 223

alias_method :regular_writer, :[]=