<commit_before>module Dreamcatch
  class Invalid < StandardError; end
  
  class Repo
    attr_reader :webdav
    attr_reader :errors
    
    def initialize(opts={})
      @errors ||= []
      @name = opts[:name]
      @dir  = opts[:dir]
      raise Dreamcatch::Invalid.new("Repo must have name") if @name.nil?
      raise Dreamcatch::Invalid.new("Repo must have dir") if @dir.nil?
      @webdav = Dreamcatch::WebDav.new(Dreamcatch::Config.remote_url, self)
    end
    
    def delete
      if webdav.exists?("#{@name}")
        webdav.delete("#{@name}")
      else
        self.add_error Dreamcatch::Error.new(%Q{#{@name} does not exists})
        nil
      end
    end
    
    def delete_local
      # TODO: delete the local repo if any
    end
    
    def rename(new_name)
      if webdav.exists?("#{@name}")
        webdav.rename(@name, new_name)
      else
        self.add_error Dreamcatch::Error.new(%Q{#{@name} does not exists})
        nil
      end
    end
    
    def save    
      if local_repo_exists?<commit_msg>remove local repo when exists<commit_after>module Dreamcatch
  class Invalid < StandardError; end
  
  class Repo
    attr_reader :webdav
    attr_reader :errors
    
    def initialize(opts={})
      @errors ||= []
      @name = opts[:name]
      @dir  = opts[:dir]
      raise Dreamcatch::Invalid.new("Repo must have name") if @name.nil?
      raise Dreamcatch::Invalid.new("Repo must have dir") if @dir.nil?
      @webdav = Dreamcatch::WebDav.new(Dreamcatch::Config.remote_url, self)
    end
    
    def delete
      if webdav.exists?("#{@name}")
        webdav.delete("#{@name}")
      else
        self.add_error Dreamcatch::Error.new(%Q{#{@name} does not exists})
        nil
      end
    end
    
    def delete_local
      if local_repo_exists?
        FileUtils.remove_dir(local_repo) == 0 ? true : (self.add_error(Dreamcatch::Error.new(%Q{#{local_repo} could not be removed})))
      else
        self.add_error Dreamcatch::Error.new(%Q{#{local_repo} does not exist locally})
        nil
      end
    end
    
    def rename(new_name)
      if webdav.exists?("#{@name}")
        webdav.rename(@name, new_name)
      else
        self.add_error Dreamcatch::Error.new(%Q{#{@name} does not exist})
        nil
      end
    end
    
    def save    
      if local_repo_exists?
{'fraction_non_alphanumeric': 0.12160413971539456, 'fraction_numerical': 0.00043122035360068997, 'mean_word_length': 2.381924198250729, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '7183547', 'n_tokens_mistral': 753, 'n_tokens_neox': 753, 'n_words': 175}