<commit_before>module Tori
  class File
    def initialize(model, title: nil, from: nil, to: nil, &block)
      @model = model
      @title = title.kind_of?(String) ? title.to_sym : title

      @from_path = if from.respond_to?(:path)
        from.path
      else
        nil
      end

      @backend = to

      @from = if from.respond_to?(:read) and from.respond_to?(:rewind)
        from.rewind
        from.read
      else
        from
      end
      @filename_callback = block
    end

    def name
      context = Context.new(@title)
      context.define_singleton_method(:__filename_callback__, filename_callback)
      context.__filename_callback__(@model)
    end
    alias to_s name

    attr_reader :from
    def from?
      !@from.nil?
    end

    def read
      backend.read name
    end

    def write(opts = nil)
      opts ||= {}
      backend.write name, @from, opts.merge(from_path: @from_path)
    end

    def delete
      backend.delete name if exist?
    end

    def filename_callback
      @filename_callback || Tori.config.filename_callback
    end

    def backend
      @backend || Tori.config.backend
    end

    def backend=(new_backend)
      @backend = new_backend
    end

    private

    def respond_to_missing?(sym, include_private)
      backend.respond_to?(sym, include_private)
    end

    def method_missing(sym, *args, &block)
      if respond_to_missing?(sym, false)
        backend.__send__ sym, name, *args, &block
      else
        fail NameError, "undefined method `#{sym}' for #{Tori.config.backend.inspect}"
      end
    end
  end
end
<commit_msg>Support from=<commit_after>module Tori
  class File
    def initialize(model, title: nil, from: nil, to: nil, &block)
      @model = model
      @title = title.kind_of?(String) ? title.to_sym : title
      @backend = to
      @filename_callback = block

      self.from = from
    end

    def name
      context = Context.new(@title)
      context.define_singleton_method(:__filename_callback__, filename_callback)
      context.__filename_callback__(@model)
    end
    alias to_s name

    def from
      @from
    end

    def from=(file)
      @from_path = if file.respond_to?(:path)
        file.path
      else
        nil
      end
      @from = if file.respond_to?(:read) and file.respond_to?(:rewind)
        file.rewind
        file.read
      else
        file
      end
    end

    def from?
      !@from.nil?
    end

    def read
      backend.read name
    end

    def write(opts = nil)
      opts ||= {}
      backend.write name, @from, opts.merge(from_path: @from_path)
    end

    def delete
      backend.delete name if exist?
    end

    def filename_callback
      @filename_callback || Tori.config.filename_callback
    end

    def backend
      @backend || Tori.config.backend
    end

    def backend=(new_backend)
      @backend = new_backend
    end

    private

    def respond_to_missing?(sym, include_private)
      backend.respond_to?(sym, include_private)
    end

    def method_missing(sym, *args, &block)
      if respond_to_missing?(sym, false)
        backend.__send__ sym, name, *args, &block
      else
        fail NameError, "undefined method `#{sym}' for #{Tori.config.backend.inspect}"
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.0900735294117647, 'fraction_numerical': 0.0, 'mean_word_length': 2.2167487684729066, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1598983', 'n_tokens_mistral': 1024, 'n_tokens_neox': 1005, 'n_words': 260}