<commit_before>require 'tmpdir'

module Sequel
  module Plugins
    module Container
      def self.apply(model, options = {})
        model.const_set "CONTAINER_TMPDIR", options[:tmp] || Dir.tmpdir
      end

      module ClassMethods
        def contains(object, options = {})
          return object.each { |o| contains(o, options) } if object.is_a? Array

          container = table_name

          class_eval <<-CONTAINED_PATH, __FILE__, __LINE__ + 1
            def #{object}_path
              return if #{object}_data.nil? || #{object}_data.empty?
              @#{object}_path ||= write_#{object}
            end
          CONTAINED_PATH

          class_eval <<-CONTAINED_URL, __FILE__, __LINE__ + 1
            def #{object}_url
              return if #{object}_data.nil? || #{object}_data.empty?
              @#{object}_path ||= write_#{object}
              @#{object}_url ||= "/#{container}/\#{id}/\#{#{object}_filename}"
            end
          CONTAINED_URL

          class_eval <<-CONTAINED_IMAGE, __FILE__, __LINE__ + 1
            def #{object}_image?
              #{object}_type[0,6] == 'image/'
            end
          CONTAINED_IMAGE

          class_eval <<-CONTAINED_DIRECTORY, __FILE__, __LINE__ + 1
            def #{object}_directory
              @asset_directory ||= FileUtils.mkdir_p(File.join(CONTAINER_TMPDIR, "#{container}", id.to_s))
            end
            protected :#{object}_directory
          CONTAINED_DIRECTORY

          class_eval <<-CONTAINED_FILENAME, __FILE__, __LINE__ + 1
            def #{object}_filename
              @#{object}_filename ||= "#{object}.\#{#{object}_extension}"
            end
            protected :#{object}_filename
          CONTAINED_FILENAME

          class_eval <<-CONTAINED_EXTENSION, __FILE__, __LINE__ + 1
            def #{object}_extension
              @#{object}_extension ||= case #{object}_type
                when /^text\\\/plain/
                  'txt'
                when /^(?:image|text)\\\/(.*)/<commit_msg>add query method for testing for content presence<commit_after>require 'tmpdir'

module Sequel
  module Plugins
    module Container
      def self.apply(model, options = {})
        model.const_set "CONTAINER_TMPDIR", options[:tmp] || Dir.tmpdir
      end

      module ClassMethods
        def contains(object, options = {})
          return object.each { |o| contains(o, options) } if object.is_a? Array

          container = table_name

          class_eval <<-CONTAINED_PATH, __FILE__, __LINE__ + 1
            def #{object}_path
              return unless #{object}?
              @#{object}_path ||= write_#{object}
            end
          CONTAINED_PATH

          class_eval <<-CONTAINED_URL, __FILE__, __LINE__ + 1
            def #{object}_url
              return unless #{object}?
              @#{object}_path ||= write_#{object}
              @#{object}_url ||= "/#{container}/\#{id}/\#{#{object}_filename}"
            end
          CONTAINED_URL

          class_eval <<-CONTAINED_QUERY, __FILE__, __LINE__ + 1
            def #{object}?
              !#{object}_data.nil?
            end
          CONTAINED_QUERY

          class_eval <<-CONTAINED_IMAGE, __FILE__, __LINE__ + 1
            def #{object}_image?
              #{object}? && #{object}_type[0,6] == 'image/'
            end
          CONTAINED_IMAGE

          class_eval <<-CONTAINED_DIRECTORY, __FILE__, __LINE__ + 1
            def #{object}_directory
              @asset_directory ||= FileUtils.mkdir_p(File.join(CONTAINER_TMPDIR, "#{container}", id.to_s))
            end
            protected :#{object}_directory
          CONTAINED_DIRECTORY

          class_eval <<-CONTAINED_FILENAME, __FILE__, __LINE__ + 1
            def #{object}_filename
              @#{object}_filename ||= "#{object}.\#{#{object}_extension}"
            end
            protected :#{object}_filename
          CONTAINED_FILENAME

          class_eval <<-CONTAINED_EXTENSION, __FILE__, __LINE__ + 1
            def #{object}_extension
              @#{object}_extension ||= case #{object}_type
                when /^text\\\/plain/
                  'txt'
                when /^(?:image|text)\\\/(.*)/
{'fraction_non_alphanumeric': 0.12371626462861238, 'fraction_numerical': 0.004060186290900406, 'mean_word_length': 1.884297520661157, 'pattern_counts': {'":': 0, '<': 29, '<?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': '735874', 'n_tokens_mistral': 1229, 'n_tokens_neox': 1187, 'n_words': 249}