<commit_before>module Travis::API::V3
  class ServiceIndex
    ALLOW_POST = ['application/json', 'application/x-www-form-urlencoded', 'multipart/form-data']
    @index_cache = {}

    def self.for(env, routes)
      access_factory = AccessControl.new(env).class
      prefix         = env['SCRIPT_NAME'.freeze]
      @index_cache[[access_factory, routes, prefix]] ||= new(access_factory, routes, prefix)
    end

    attr_reader :access_factory, :routes, :json_home_response, :json_response, :prefix

    def initialize(access_factory, routes, prefix)
      @prefix                  = prefix || ''
      @access_factory, @routes = access_factory, routes
      @json_response           = V3.response(render_json,      content_type: 'application/json'.freeze)
      @json_home_response      = V3.response(render_json_home, content_type: 'application/json-home'.freeze)
    end

    def config
      # TODO: move this somewhere else?
      pusher_config = (Travis.config.pusher_ws || Travis.config.pusher.to_h || {}).to_hash.slice(:scheme, :host, :port, :path, :key, :secure, :private)
      {
        host:   Travis.config.client_domain || Travis.config.host,
        github: V3::GitHub.client_config,
        pusher: pusher_config
      }
    end

    def all_resources
      @all_resources ||= begin
        home_actions = {
          find: [{
            :@type          => :template,
            :request_method => :GET,
            :uri_template   => prefix + ?/
          }]
        }

        all = routes.resources + [
          Routes::Resource.new(:broadcast), # dummy as there are only broadcasts routes right now
          Routes::Resource.new(:commit),    # dummy as commits can only be embedded
          Routes::Resource.new(:request),   # dummy as there are only requests routes right now
          Routes::Resource.new(:stage),     # dummy as there is no stage endpoint at the moment
          Routes::Resource.new(:error),
          Routes::Resource.new(:home,     attributes: [:config, :errors, :resources], actions: home_actions),
          Routes::Resource.new(:resource, attributes: [:actions, :attributes, :representations, :access_rights]),
          Routes::Resource.new(:template, attributes: [:request_method, :uri_template])
        ]

        all.sort_by(&:display_identifier)
      end
    end
<commit_msg>add dummy message resource (#619)<commit_after>module Travis::API::V3
  class ServiceIndex
    ALLOW_POST = ['application/json', 'application/x-www-form-urlencoded', 'multipart/form-data']
    @index_cache = {}

    def self.for(env, routes)
      access_factory = AccessControl.new(env).class
      prefix         = env['SCRIPT_NAME'.freeze]
      @index_cache[[access_factory, routes, prefix]] ||= new(access_factory, routes, prefix)
    end

    attr_reader :access_factory, :routes, :json_home_response, :json_response, :prefix

    def initialize(access_factory, routes, prefix)
      @prefix                  = prefix || ''
      @access_factory, @routes = access_factory, routes
      @json_response           = V3.response(render_json,      content_type: 'application/json'.freeze)
      @json_home_response      = V3.response(render_json_home, content_type: 'application/json-home'.freeze)
    end

    def config
      # TODO: move this somewhere else?
      pusher_config = (Travis.config.pusher_ws || Travis.config.pusher.to_h || {}).to_hash.slice(:scheme, :host, :port, :path, :key, :secure, :private)
      {
        host:   Travis.config.client_domain || Travis.config.host,
        github: V3::GitHub.client_config,
        pusher: pusher_config
      }
    end

    def all_resources
      @all_resources ||= begin
        home_actions = {
          find: [{
            :@type          => :template,
            :request_method => :GET,
            :uri_template   => prefix + ?/
          }]
        }

        all = routes.resources + [
          Routes::Resource.new(:broadcast), # dummy as there are only broadcasts routes right now
          Routes::Resource.new(:commit),    # dummy as commits can only be embedded
          Routes::Resource.new(:message),   # dummy as there is only a messages route right now
          Routes::Resource.new(:request),   # dummy as there are only requests routes right now
          Routes::Resource.new(:stage),     # dummy as there is no stage endpoint at the moment
          Routes::Resource.new(:error),
          Routes::Resource.new(:home,     attributes: [:config, :errors, :resources], actions: home_actions),
          Routes::Resource.new(:resource, attributes: [:actions, :attributes, :representations, :access_rights]),
          Routes::Resource.new(:template, attributes: [:request_method, :uri_template])
        ]

        all.sort_by(&:display_identifier)
      end
    end

{'fraction_non_alphanumeric': 0.1201923076923077, 'fraction_numerical': 0.00229933110367893, 'mean_word_length': 2.7208398133748055, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1989409', 'n_tokens_mistral': 1397, 'n_tokens_neox': 1371, 'n_words': 309}