Class: Zold::NoSpamEntrance
- Inherits:
-
Object
- Object
- Zold::NoSpamEntrance
- Defined in:
- lib/zold/node/nospam_entrance.rb
Overview
The no-spam entrance
Instance Method Summary collapse
-
#initialize(entrance, period: 60 * 60, log: Log::NULL) ⇒ NoSpamEntrance
constructor
A new instance of NoSpamEntrance.
-
#push(id, body) ⇒ Object
Returns a list of modifed wallets (as Zold::Id).
- #start ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(entrance, period: 60 * 60, log: Log::NULL) ⇒ NoSpamEntrance
Returns a new instance of NoSpamEntrance.
36 37 38 39 40 41 |
# File 'lib/zold/node/nospam_entrance.rb', line 36 def initialize(entrance, period: 60 * 60, log: Log::NULL) @entrance = entrance @log = log @period = period @zache = Zache.new end |
Instance Method Details
#push(id, body) ⇒ Object
Returns a list of modifed wallets (as Zold::Id)
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/zold/node/nospam_entrance.rb', line 53 def push(id, body) before = @zache.get(id.to_s, lifetime: @period) { '' } after = hash(id, body) if before == after @log.debug("Spam of #{id} ignored #{Size.new(body.length)}") return [] end @zache.put(id.to_s, after) @entrance.push(id, body) end |
#start ⇒ Object
43 44 45 46 |
# File 'lib/zold/node/nospam_entrance.rb', line 43 def start raise 'Block must be given to start()' unless block_given? @entrance.start { yield(self) } end |
#to_json ⇒ Object
48 49 50 |
# File 'lib/zold/node/nospam_entrance.rb', line 48 def to_json @entrance.to_json end |