<commit_before>require "fog/core/model"

module Fog
  module Storage
    class GoogleJSON
      class File < Fog::Model
        identity :key, :aliases => "Key"

        # TODO: Verify
        attribute :acl
        attribute :predefined_acl
        attribute :cache_control,       :aliases => "cacheControl"
        attribute :content_disposition, :aliases => "contentDisposition"
        attribute :content_encoding,    :aliases => "contentEncoding"
        attribute :content_length,      :aliases => "size", :type => :integer
        attribute :content_md5,         :aliases => "md5Hash"
        attribute :content_type,        :aliases => "contentType"
        attribute :crc32c
        attribute :etag,                :aliases => "etag"
        attribute :time_created,        :aliases => "timeCreated"
        attribute :last_modified,       :aliases => "updated"
        attribute :generation
        attribute :metageneration
        attribute :metadata
        attribute :self_link,           :aliases => "selfLink"
        attribute :media_link,          :aliases => "mediaLink"
        attribute :owner
        attribute :storage_class, :aliases => "storageClass"

        @valid_predefined_acls = %w(private projectPrivate bucketOwnerFullControl bucketOwnerRead authenticatedRead publicRead)

        def predefined_acl=(new_acl)
          unless @valid_predefined_acls.include?(new_acl)
            raise ArgumentError.new("acl must be one of [#{@valid_predefined_acls.join(', ')}]")
          end
          @predefined_acl = new_acl
        end

        # TODO: Implement object ACLs
        # def acl=(new_acl)
        #   valid_acls = ["private", "projectPrivate", "bucketOwnerFullControl", "bucketOwnerRead", "authenticatedRead", "publicRead"]
        #   unless valid_acls.include?(new_acl)
        #     raise ArgumentError.new("acl must be one of [#{valid_acls.join(', ')}]")
        #   end
        #   @acl = new_acl
        # end

        # TODO: Verify
        def body
          attributes[:body] ||= last_modified && (file = collection.get(identity)) ? file.body : ""
        end

        # TODO: Verify
        def body=(new_body)
          attributes[:body] = new_body
        end

        attr_reader :directory

        # TODO: Verify
        def copy(target_directory_key, target_file_key)
          requires :directory, :key
          service.copy_object(directory.key, key, target_directory_key, target_file_key)
          target_directory = service.directories.new(:key => target_directory_key)
          target_directory.files.get(target_file_key)
        end

        # TODO: Verify
        def destroy
          requires :directory, :key
          begin
            service.delete_object(directory.key, key)
          rescue Excon::Errors::NotFound
          end
          true
        end

        # TODO: Verify
        remove_method :metadata=
        def metadata=(new_metadata)
          metadata.merge!(new_metadata)
        end

        # TODO: Verify
        remove_method :owner=
        def owner=(new_owner)<commit_msg>Match file.destroy return values and logic to directory.destroy<commit_after>require "fog/core/model"

module Fog
  module Storage
    class GoogleJSON
      class File < Fog::Model
        identity :key, :aliases => "Key"

        # TODO: Verify
        attribute :acl
        attribute :predefined_acl
        attribute :cache_control,       :aliases => "cacheControl"
        attribute :content_disposition, :aliases => "contentDisposition"
        attribute :content_encoding,    :aliases => "contentEncoding"
        attribute :content_length,      :aliases => "size", :type => :integer
        attribute :content_md5,         :aliases => "md5Hash"
        attribute :content_type,        :aliases => "contentType"
        attribute :crc32c
        attribute :etag,                :aliases => "etag"
        attribute :time_created,        :aliases => "timeCreated"
        attribute :last_modified,       :aliases => "updated"
        attribute :generation
        attribute :metageneration
        attribute :metadata
        attribute :self_link,           :aliases => "selfLink"
        attribute :media_link,          :aliases => "mediaLink"
        attribute :owner
        attribute :storage_class, :aliases => "storageClass"

        @valid_predefined_acls = %w(private projectPrivate bucketOwnerFullControl bucketOwnerRead authenticatedRead publicRead)

        def predefined_acl=(new_acl)
          unless @valid_predefined_acls.include?(new_acl)
            raise ArgumentError.new("acl must be one of [#{@valid_predefined_acls.join(', ')}]")
          end
          @predefined_acl = new_acl
        end

        # TODO: Implement object ACLs
        # def acl=(new_acl)
        #   valid_acls = ["private", "projectPrivate", "bucketOwnerFullControl", "bucketOwnerRead", "authenticatedRead", "publicRead"]
        #   unless valid_acls.include?(new_acl)
        #     raise ArgumentError.new("acl must be one of [#{valid_acls.join(', ')}]")
        #   end
        #   @acl = new_acl
        # end

        # TODO: Verify
        def body
          attributes[:body] ||= last_modified && (file = collection.get(identity)) ? file.body : ""
        end

        # TODO: Verify
        def body=(new_body)
          attributes[:body] = new_body
        end

        attr_reader :directory

        # TODO: Verify
        def copy(target_directory_key, target_file_key)
          requires :directory, :key
          service.copy_object(directory.key, key, target_directory_key, target_file_key)
          target_directory = service.directories.new(:key => target_directory_key)
          target_directory.files.get(target_file_key)
        end

        # TODO: Verify
        def destroy
          requires :directory, :key
          service.delete_object(directory.key, key)
          true
        rescue Excon::Errors::NotFound
          false
        end

        # TODO: Verify
        remove_method :metadata=
        def metadata=(new_metadata)
          metadata.merge!(new_metadata)
        end

        # TODO: Verify
        remove_method :owner=
        def owner=(new_owner)
{'fraction_non_alphanumeric': 0.0946822308690013, 'fraction_numerical': 0.0012970168612191958, 'mean_word_length': 2.2247778358599057, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '2967587', 'n_tokens_mistral': 1689, 'n_tokens_neox': 1671, 'n_words': 393}