lib/rivendell/import/notifier/base.rb in rivendell-import-0.0.1 vs lib/rivendell/import/notifier/base.rb in rivendell-import-0.0.2

- old
+ new

@@ -56,14 +56,19 @@ self.parameters = ActiveSupport::JSON.decode(raw_parameters) if raw_parameters.present? end after_initialize :read_parameters + def parameters_hash + parameters_as_string = parameters.sort_by { |p| p.first.to_s }.flatten.join('-') + Digest::SHA256.hexdigest parameters_as_string + end + def write_parameters if parameters.present? write_attribute :parameters, parameters.to_json - write_attribute :key, parameters.hash + write_attribute :key, parameters_hash else write_attribute :parameters, nil write_attribute :key, nil end end @@ -74,10 +79,10 @@ new_notifier = case options.delete(:by) when :email Mail.new options.merge(:to => target) end - key = new_notifier.parameters.hash + key = new_notifier.parameters_hash if existing_notifier = where(:type => new_notifier.type, :key => key).first existing_notifier else new_notifier.save! new_notifier