lib/reactor/event.rb in reactor-0.8.1 vs lib/reactor/event.rb in reactor-0.8.2

- old
+ new

@@ -1,11 +1,9 @@ class Reactor::Event include Reactor::OptionallySubclassable include Sidekiq::Worker - class UnserializableModelKeysIncluded < StandardError; end; - attr_accessor :data def initialize(data = {}) self.data = {}.with_indifferent_access data.each do |key, value| @@ -35,12 +33,10 @@ def perform(name, data) new.perform(name, data) end def publish(name, data = {}) - enforce_serializable_model_keys!(data) - message = new(data.merge(event: name)) if message.at.nil? perform_async name, message.data elsif message.at.future? @@ -56,25 +52,9 @@ job.score.to_i == data[:was].to_i end return if job.nil? job.delete publish(name, data.except(:was)) if data[:at].future? - end - - private - - def enforce_serializable_model_keys!(event_signature) - event_signature = event_signature.stringify_keys - serializable_models = event_signature.keys.map(&:to_s).select { |k| k.end_with?('_id') || k.end_with?('_type') } - .map { |k| k.gsub(/_id\Z/, '') } - .map { |k| k.gsub(/_type\Z/, '') } - .uniq - - serializable_models.each do |model_relation_name| - raise UnserializableModelKeysIncluded, "#{model_relation_name}_type is missing corresponding _id key" if event_signature["#{model_relation_name}_id"].blank? - raise UnserializableModelKeysIncluded, "#{model_relation_name}_id is missing corresponding _type key" if event_signature["#{model_relation_name}_type"].blank? - - end end end private