Class: Zold::NoDupEntrance

Inherits:
Object
  • Object
show all
Defined in:
lib/zold/node/nodup_entrance.rb

Overview

The entrance that ignores dups

Instance Method Summary collapse

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

#startObject



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_jsonObject



47
48
49
# File 'lib/zold/node/nodup_entrance.rb', line 47

def to_json
  @entrance.to_json
end