<commit_before>require "fog"
require "refile"
require "refile/fog/version"

module Refile
  module Fog
    class Backend
      attr_reader :directory

      def initialize(directory:, max_size: nil, prefix: nil, hasher: Refile::RandomHasher.new, connection: nil, **options)
        @connection = connection || ::Fog::Storage.new(options)
        @prefix = prefix
        @hasher = hasher
        @max_size = max_size

        @directory = @connection.directories.new(key: directory)
      end

      def upload(uploadable)
        Refile.verify_uploadable(uploadable, @max_size)

        id = @hasher.hash(uploadable)

        @directory.files.create(key: path(id), body: uploadable.read)<commit_msg>Use new `verify_uploadable` api for validation<commit_after>require "fog"
require "refile"
require "refile/fog/version"

module Refile
  module Fog
    class Backend
      extend Refile::BackendMacros

      attr_reader :directory, :max_size

      def initialize(directory:, max_size: nil, prefix: nil, hasher: Refile::RandomHasher.new, connection: nil, **options)
        @connection = connection || ::Fog::Storage.new(options)
        @prefix = prefix
        @hasher = hasher
        @max_size = max_size

        @directory = @connection.directories.new(key: directory)
      end

      verify_uploadable def upload(uploadable)
        id = @hasher.hash(uploadable)

        @directory.files.create(key: path(id), body: uploadable.read)
{'fraction_non_alphanumeric': 0.10756419153365718, 'fraction_numerical': 0.0, 'mean_word_length': 3.3044776119402983, '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': '1256442', 'n_tokens_mistral': 443, 'n_tokens_neox': 432, 'n_words': 102}