Class: Carnivore::Utils::MessageRegistry
- Inherits:
-
Object
- Object
- Carnivore::Utils::MessageRegistry
- Includes:
- Zoidberg::Shell
- Defined in:
- lib/carnivore/utils/message_registry.rb
Overview
Registry used for preventing duplicate message processing
Instance Method Summary collapse
-
#initialize ⇒ MessageRegistry
constructor
Create new instance.
-
#push(item) ⇒ self
Register checksum into registry.
-
#sha(thing) ⇒ String
Generate checksum for given item.
-
#valid?(message) ⇒ TrueClass, FalseClass
Validity of message (not found within registry).
Constructor Details
#initialize ⇒ MessageRegistry
Create new instance
10 11 12 13 |
# File 'lib/carnivore/utils/message_registry.rb', line 10 def initialize @store = [] @size = 100 end |
Instance Method Details
#push(item) ⇒ self
Register checksum into registry
32 33 34 35 36 37 38 |
# File 'lib/carnivore/utils/message_registry.rb', line 32 def push(item) @store.push(item) if(@store.size > @size) @store.shift end self end |
#sha(thing) ⇒ String
Generate checksum for given item
44 45 46 47 48 49 |
# File 'lib/carnivore/utils/message_registry.rb', line 44 def sha(thing) unless(thing.is_a?(String)) thing = MultiJson.dump(thing) end (Digest::SHA512.new << thing).hexdigest end |
#valid?(message) ⇒ TrueClass, FalseClass
Validity of message (not found within registry)
19 20 21 22 23 24 25 26 |
# File 'lib/carnivore/utils/message_registry.rb', line 19 def valid?() checksum = sha() found = @store.include?(checksum) unless(found) push(checksum) end !found end |