<commit_before>require 'rubygems'
require 'pathname'
require Pathname(__FILE__).dirname + 'couchdb_adapter/version'
gem 'dm-core', DataMapper::More::CouchDBAdapter::VERSION
require 'dm-core'
require 'json'
require 'ostruct'
require 'net/http'
require 'uri'
require Pathname(__FILE__).dirname + 'couchdb_adapter/attachments'
require Pathname(__FILE__).dirname + 'couchdb_adapter/json_object'
require Pathname(__FILE__).dirname + 'couchdb_adapter/view'

module DataMapper
  module Resource
    # Converts a Resource to a JSON representation.
    def to_json(dirty = false)
      property_list = self.class.properties.select { |key, value| dirty ? self.dirty_attributes.key?(key) : true }
      data = {}
      for property in property_list do
        raise PersistenceError, '+couchdb_type+ is a reserved column name', caller if property.field == 'couchdb_type'
        data[property.field] =
          if property.type.respond_to?(:dump)
            property.type.dump(property.get!(self), property)
          else
            property.get!(self)
          end
      end
      data.delete(:_attachments) if data[:_attachments].nil?
      data[:couchdb_type] = self.class.storage_name(repository.name)
      return data.to_json
    end
  end
end
<commit_msg>get rid of empty attachments too, just in case<commit_after>require 'rubygems'
require 'pathname'
require Pathname(__FILE__).dirname + 'couchdb_adapter/version'
gem 'dm-core', DataMapper::More::CouchDBAdapter::VERSION
require 'dm-core'
require 'json'
require 'ostruct'
require 'net/http'
require 'uri'
require Pathname(__FILE__).dirname + 'couchdb_adapter/attachments'
require Pathname(__FILE__).dirname + 'couchdb_adapter/json_object'
require Pathname(__FILE__).dirname + 'couchdb_adapter/view'

module DataMapper
  module Resource
    # Converts a Resource to a JSON representation.
    def to_json(dirty = false)
      property_list = self.class.properties.select { |key, value| dirty ? self.dirty_attributes.key?(key) : true }
      data = {}
      for property in property_list do
        raise PersistenceError, '+couchdb_type+ is a reserved column name', caller if property.field == 'couchdb_type'
        data[property.field] =
          if property.type.respond_to?(:dump)
            property.type.dump(property.get!(self), property)
          else
            property.get!(self)
          end
      end
      data.delete(:_attachments) if data[:_attachments].nil? || data[:_attachments].empty?
      data[:couchdb_type] = self.class.storage_name(repository.name)
      return data.to_json
    end
  end
end

{'fraction_non_alphanumeric': 0.10718446601941747, 'fraction_numerical': 0.0, 'mean_word_length': 3.7881040892193307, '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': '6980767', 'n_tokens_mistral': 772, 'n_tokens_neox': 770, 'n_words': 183}