Class: Zold::NoDupEntrance
- Inherits:
-
Object
- Object
- Zold::NoDupEntrance
- Defined in:
- lib/zold/node/nodup_entrance.rb
Overview
The entrance that ignores dups
Instance Method Summary collapse
-
#initialize(entrance, wallets, log: Log::NULL) ⇒ NoDupEntrance
constructor
A new instance of NoDupEntrance.
-
#push(id, body) ⇒ Object
Returns a list of modifed wallets (as Zold::Id).
- #start ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(entrance, wallets, log: Log::NULL) ⇒ NoDupEntrance
Returns a new instance of NoDupEntrance.
36 37 38 39 40 |
# File 'lib/zold/node/nodup_entrance.rb', line 36 def initialize(entrance, wallets, log: Log::NULL) @entrance = entrance @wallets = wallets @log = log end |
Instance Method Details
#push(id, body) ⇒ Object
Returns a list of modifed wallets (as Zold::Id)
52 53 54 55 56 57 58 59 60 61 |
# File 'lib/zold/node/nodup_entrance.rb', line 52 def push(id, body) before = @wallets.acq(id) { |w| w.exists? ? w.digest : '' } after = OpenSSL::Digest::SHA256.new(body).hexdigest if before == after @log.debug("Duplicate of #{id} ignored #{Size.new(body.length)}") return [] end @log.debug("New content for #{id} arrived #{Size.new(body.length)}") @entrance.push(id, body) end |
#start ⇒ Object
42 43 44 45 |
# File 'lib/zold/node/nodup_entrance.rb', line 42 def start raise 'Block must be given to start()' unless block_given? @entrance.start { yield(self) } end |
#to_json ⇒ Object
47 48 49 |
# File 'lib/zold/node/nodup_entrance.rb', line 47 def to_json @entrance.to_json end |