<commit_before>class Barkdog::Driver
  include Barkdog::Logger::Helper

  def initialize(dog, options = {})
    @dog = dog
    @options = options
  end

  def create_monitor(name, attrs)
    updated = false
    log(:info, "Create Monitor: #{name}", :color => :cyan)

    if @options[:ignore_silenced]
      attrs['options'].delete('silenced')
    end

    unless @options[:dry_run]
      @dog.monitor(
        attrs['type'],
        attrs['query'],
        :name => name,
        :message => attrs['message'],
        :options => attrs['options']
      )

      updated = true
    end

    updated
  end

  def delete_monitor(name, attrs)
    updated = false
    log(:info, "Delete Monitor: #{name}", :color => :red)

    unless @options[:dry_run]
      @dog.delete_monitor(attrs['id'])
      updated = true
    end

    updated
  end

  def update_monitor(name, expected, actual)
    updated = false

    if @options[:ignore_silenced]
      expected['options'].delete('silenced')
      actual['options'].delete('silenced')
    end

    diffy = Diffy::Diff.new(
      Barkdog::DSL::Converter.convert({name => actual}),
      Barkdog::DSL::Converter.convert({name => expected}),
      :diff => "-u"
    )

    if diffy.diff.size > 0
      log(:info, "Update Monitor: #{name}", :color => :cyan)
      log(:info, diffy.to_s(:color), :color => false )
      unless @options[:dry_run]
        @dog.update_monitor(
          expected['id'],<commit_msg>Fix diff color<commit_after>class Barkdog::Driver
  include Barkdog::Logger::Helper

  def initialize(dog, options = {})
    @dog = dog
    @options = options
  end

  def create_monitor(name, attrs)
    updated = false
    log(:info, "Create Monitor: #{name}", :color => :cyan)

    if @options[:ignore_silenced]
      attrs['options'].delete('silenced')
    end

    unless @options[:dry_run]
      @dog.monitor(
        attrs['type'],
        attrs['query'],
        :name => name,
        :message => attrs['message'],
        :options => attrs['options']
      )

      updated = true
    end

    updated
  end

  def delete_monitor(name, attrs)
    updated = false
    log(:info, "Delete Monitor: #{name}", :color => :red)

    unless @options[:dry_run]
      @dog.delete_monitor(attrs['id'])
      updated = true
    end

    updated
  end

  def update_monitor(name, expected, actual)
    updated = false

    if @options[:ignore_silenced]
      expected['options'].delete('silenced')
      actual['options'].delete('silenced')
    end

    diffy = Diffy::Diff.new(
      Barkdog::DSL::Converter.convert({name => actual}),
      Barkdog::DSL::Converter.convert({name => expected}),
      :diff => "-u"
    )

    if diffy.diff.size > 0
      log(:info, "Update Monitor: #{name}", :color => :cyan)
      log(:info, diffy.to_s(@options[:color] ? :color : :text), :color => false)

      unless @options[:dry_run]
        @dog.update_monitor(
          expected['id'],
{'fraction_non_alphanumeric': 0.15719178082191781, 'fraction_numerical': 0.0006849315068493151, 'mean_word_length': 2.7593307593307594, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '4187886', 'n_tokens_mistral': 919, 'n_tokens_neox': 897, 'n_words': 199}