<commit_before>require 'travis/api/serialize/formats'
require 'travis/api/serialize/v0'
require 'travis/api/serialize/v1'

module Travis
  module Api
    module Serialize
      DEFAULT_VERSION = 'v2'

      class << self
        def data(resource, options = {})
          new(resource, options).data
        end

        def builder(resource, options = {})
          target  = (options[:for] || 'http').to_s.camelize
          version = (options[:version] || default_version(options)).to_s.camelize
          type    = (options[:type] || type_for(resource)).to_s.camelize.split('::')
          ([version, target] + type).inject(self) do |const, name|
            begin
              if const && const.const_defined?(name.to_s.camelize, false)
                const.const_get(name, false)
              else
                nil
              end
            rescue NameError
              nil
            end
          end
        end

        def new(resource, options = {})
          builder = builder(resource, options) || raise(ArgumentError, "cannot serialize #{resource.inspect}, options: #{options.inspect}")
          builder.new(resource, options[:params] || {})
        end

        private

          def type_for(resource)
            if arel_relation?(resource)
              type = resource.klass.name.pluralize
            else
              type = resource.class
              type = type.base_class if active_record?(type)
              type = type.name
            end
            type.split('::').last
          end

          def arel_relation?(object)
            object.respond_to?(:klass)
          end

          def active_record?(object)
            object.respond_to?(:base_class)
          end

          def default_version(options)
            if options[:for].to_s.downcase == "pusher"
              "v0"
            else
              DEFAULT_VERSION
            end
          end
      end<commit_msg>Add more debugging around v2 json serialization stuff<commit_after>require 'travis/api/serialize/formats'
require 'travis/api/serialize/v0'
require 'travis/api/serialize/v1'

module Travis
  module Api
    module Serialize
      DEFAULT_VERSION = 'v2'

      class << self
        def data(resource, options = {})
          new(resource, options).data
        end

        def builder(resource, options = {})
          Travis.logger.debug("#{self.class.name}#builder resource=#{resource.inspect} options=#{options.inspect}")
          target  = (options[:for] || 'http').to_s.camelize
          version = (options[:version] || default_version(options)).to_s.camelize
          type    = (options[:type] || type_for(resource)).to_s.camelize.split('::')
          ([version, target] + type).inject(self) do |const, name|
            Travis.logger.debug("#{self.class.name}#builder inject const=#{const.inspect} name=#{name.inspect}")
            begin
              if const && const.const_defined?(name.to_s.camelize, false)
                const.const_get(name, false)
              else
                nil
              end
            rescue NameError
              nil
            end
          end
        end

        def new(resource, options = {})
          builder = builder(resource, options) || raise(ArgumentError, "cannot serialize #{resource.inspect}, options: #{options.inspect}")
          builder.new(resource, options[:params] || {})
        end

        private

          def type_for(resource)
            Travis.logger.debug("#{self.class.name}#type_for in resource=#{resource.inspect}")
            if arel_relation?(resource)
              type = resource.klass.name.pluralize
            else
              type = resource.class
              type = type.base_class if active_record?(type)
              type = type.name
            end
            type.split('::').last.tap do |value|
              Travis.logger.debug("#{self.class.name}#type_for out value=#{value.inspect}")
            end
          end

          def arel_relation?(object)
            object.respond_to?(:klass)
          end

          def active_record?(object)
            object.respond_to?(:base_class)
          end

          def default_version(options)
            if options[:for].to_s.downcase == "pusher"
              "v0"
            else
              DEFAULT_VERSION
            end
          end
      end
{'fraction_non_alphanumeric': 0.11049850677693544, 'fraction_numerical': 0.002067539627842867, 'mean_word_length': 1.7470031545741325, 'pattern_counts': {'":': 0, '<': 7, '<?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': '3921546', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1201, 'n_words': 242}