Class: Vash
- Inherits:
-
Hash
- Object
- Hash
- Vash
- Defined in:
- lib/logstash/codecs/netflow/util.rb
Overview
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, *args) ⇒ Object
- #cleanup! ⇒ Object
- #clear(key) ⇒ Object
-
#initialize(constructor = {}) ⇒ Vash
constructor
A new instance of Vash.
- #merge(hsh) ⇒ Object
- #regular_reader ⇒ Object
- #regular_writer ⇒ Object
Constructor Details
#initialize(constructor = {}) ⇒ Vash
Returns a new instance of Vash.
146 147 148 149 150 151 152 153 154 |
# File 'lib/logstash/codecs/netflow/util.rb', line 146 def initialize(constructor = {}) @register ||= {} if constructor.is_a?(Hash) super() merge(constructor) else super(constructor) end end |
Instance Method Details
#[](key) ⇒ Object
159 160 161 162 163 |
# File 'lib/logstash/codecs/netflow/util.rb', line 159 def [](key) sterilize(key) clear(key) if expired?(key) regular_reader(key) end |
#[]=(key, *args) ⇒ Object
165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/logstash/codecs/netflow/util.rb', line 165 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
184 185 186 187 |
# File 'lib/logstash/codecs/netflow/util.rb', line 184 def cleanup! now = Time.now.to_i @register.map {|k,v| clear(k) if v < now} end |
#clear(key) ⇒ Object
189 190 191 192 193 |
# File 'lib/logstash/codecs/netflow/util.rb', line 189 def clear(key) sterilize(key) @register.delete key self.delete key end |
#merge(hsh) ⇒ Object
179 180 181 182 |
# File 'lib/logstash/codecs/netflow/util.rb', line 179 def merge(hsh) hsh.map {|key,value| self[sterile(key)] = hsh[key]} self end |
#regular_reader ⇒ Object
157 |
# File 'lib/logstash/codecs/netflow/util.rb', line 157 alias_method :regular_reader, :[] |
#regular_writer ⇒ Object
156 |
# File 'lib/logstash/codecs/netflow/util.rb', line 156 alias_method :regular_writer, :[]= |