<commit_before>require 'common_mob'

class FileTarget < AngryMob::Target
  nickname 'file'
  include CommonMob::FileHelper

  default_action
  def create
    if args.src
      copy_resource resource(args.src)
    elsif args.string
      create_string
    end

    set_file_ownership
  end

  def delete
    if exist?
      log "deleting #{default_object}"
      unlink
    end
  end

  protected

  def default_object
    Pathname(super)
  end

  def state
    {
      :sha512 => sha512(default_object)
    }
  end

  def src
    resource(args.src)
  end

  def validate!
    if !args.actions.include?('delete')
      if args.src?
        problem!(":src #{src} doesn't exist" ) unless src.exist?
      elsif !args.src? && !args.string?
        problem!("please specify one of :src or :string")
      end
    end
  end


  def copy_resource(src)
    if sha512(src) != before_state[:sha512]<commit_msg>add modification (for tweaking file mode etc)<commit_after>require 'common_mob'

class FileTarget < AngryMob::Target
  nickname 'file'
  include CommonMob::FileHelper

  default_action
  def create
    if args.src
      copy_resource resource(args.src)
    elsif args.string
      create_string
    end

    set_file_ownership
  end

  def delete
    if exist?
      log "deleting #{default_object}"
      unlink
    end
  end

  def modify
    set_file_ownership
  end

  protected

  def default_object
    Pathname(super)
  end

  def state
    {
      :sha512 => sha512(default_object)
    }
  end

  def src
    resource(args.src)
  end

  def validate!
    unless action?(:delete, :modify)
      if args.src?
        problem!(":src #{src} doesn't exist" ) unless src.exist?
      elsif !args.src? && !args.string?
        problem!("please specify one of :src or :string")
      end
    end
  end


  def copy_resource(src)
    if sha512(src) != before_state[:sha512]
{'fraction_non_alphanumeric': 0.0876068376068376, 'fraction_numerical': 0.01282051282051282, 'mean_word_length': 2.5676190476190475, 'pattern_counts': {'":': 2, '<': 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': '5063208', 'n_tokens_mistral': 648, 'n_tokens_neox': 607, 'n_words': 162}