module EventAggregator # Public: TODO: Could potentially turn this into a module. # # module OtherSingleton # @index = -1 # @colors = %w{ red green blue } # def self.change # @colors[(@index += 1) % @colors.size] # end # end class Aggregator class < message will be sent async. Default true # consisten_data - true => the same object will be sent to all recievers. Default false def self.message_publish ( message, async = true, consisten_data = false ) raise "Invalid message" unless message.respond_to?(:message_type) && message.respond_to?(:data) @@listeners[message.message_type].each do |l| if l[1].respond_to? :call case [async, consisten_data] when [true, true] then EventAggregator::MessageJob.new.async.perform(message.data, l[1]) when [true, false] then EventAggregator::MessageJob.new.async.perform(message.data.clone, l[1]) when [false, true] then EventAggregator::MessageJob.new.perform( message.data, l[1]) when [false, false] then EventAggregator::MessageJob.new.perform( message.data.clone, l[1]) end end end end end end