<commit_before>require 'pebblebed'
require_relative 'models/post'

class RiverNotifications < ActiveRecord::Observer

  observe Post

  def self.river
    @river ||= Pebbles::River::River.new
  end

  def after_create(object)
    if object.is_a?(Post)
      LOGGER.info("RIVERNOTF: after_create #{"#{object.klass}:#{object.canonical_path}$#{object.id}"}")
    end
    if should_publish?(object)
      prepare_for_publish(object, :create)
    end
    nil
  end

  def after_update(object)
    if object.is_a?(Post)
      LOGGER.info("RIVERNOTF: after_update #{"#{object.klass}:#{object.canonical_path}$#{object.id}"}")
    end
    if should_publish?(object)
      if object.deleted?
        prepare_for_publish(object, :delete, :soft_deleted => true)
      else
        prepare_for_publish(object, :update)
      end
    end
    nil
  end

  def after_destroy(object)
    if should_publish?(object)
      prepare_for_publish(object, :delete)
    end
    nil
  end

  def publish!(params)
    self.class.river.publish(params)
  end

  private

    def should_publish?(object)<commit_msg>Remove loggin, turned out rabbitmq was the culprit<commit_after>require 'pebblebed'
require_relative 'models/post'

class RiverNotifications < ActiveRecord::Observer

  observe Post

  def self.river
    @river ||= Pebbles::River::River.new
  end

  def after_create(object)
    if should_publish?(object)
      prepare_for_publish(object, :create)
    end
    nil
  end

  def after_update(object)
    if should_publish?(object)
      if object.deleted?
        prepare_for_publish(object, :delete, :soft_deleted => true)
      else
        prepare_for_publish(object, :update)
      end
    end
    nil
  end

  def after_destroy(object)
    if should_publish?(object)
      prepare_for_publish(object, :delete)
    end
    nil
  end

  def publish!(params)
    self.class.river.publish(params)
  end

  private

    def should_publish?(object)
{'fraction_non_alphanumeric': 0.1020196789228379, 'fraction_numerical': 0.0, 'mean_word_length': 3.3710407239819005, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5365028', 'n_tokens_mistral': 633, 'n_tokens_neox': 639, 'n_words': 130}