Sha256: 171ed44aada3f7210230dd892136a320b36ab08ba6b35a777284d6445118445d
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
module Basquiat module Adapters # An adapter to be used in testing class Test include Basquiat::Adapters::Base class << self def events @events ||= Hash.new { |hash, key| hash[key] = [] } end def clean @events.clear if @events end end attr_reader :options def default_options @event_names = [] { host: '127.0.0.1', port: 123_456, durable: true } end def publish(event, message, _single_message = true) self.class.events[event] << Basquiat::Json.encode(message) end def events(key) self.class.events[key] end def subscribe_to(event_name, proc) @event_names << event_name procs[event_name] = proc end def listen(*) event = subscribed_event msg = self.class.events[event].shift msg ? procs[event].call(Basquiat::Json.decode(msg)) : nil end private def subscribed_event event = @event_names.first @event_names.rotate! event end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
basquiat-1.1.1 | lib/basquiat/adapters/test_adapter.rb |