<commit_before>import { singularize, capitalize, camelize } from 'ember-cli-mirage/utils/inflector';
import _isArray from 'lodash/lang/isArray';

const allDigitsRegex = /^\d+$/;

export default class BaseShorthandRouteHandler {

  constructor(dbOrSchema, serializerOrRegistry, shorthand, options) {
    this.dbOrSchema = dbOrSchema;
    this.serializerOrRegistry = serializerOrRegistry;
    this.shorthand = shorthand;
    this.options = options;
  }

  handle(request) {
    let type = _isArray(this.shorthand) ? 'array' : typeof this.shorthand;
    let typeHandler = `handle${capitalize(type)}Shorthand`;

    return this[typeHandler](this.shorthand, this.dbOrSchema, request, this.options);
  }

  _getIdForRequest(request) {
    let id;

    if (request && request.params && request.params.id) {
      id = request.params.id;
      // If parses, coerce to integer
      if (typeof id === "string" && allDigitsRegex.test(id)) {
        id = parseInt(request.params.id, 10);
      }
    }

    return id;
  }

  _getUrlForRequest(request) {
    let url;

    if (request && request.url) {
      url = request.url;
    }

    return url;
  }

  _getTypeFromUrl(url, hasId) {
    let urlNoId = hasId ? url.substr(0, url.lastIndexOf('/')) : url;
    let urlSplit = urlNoId.split('?');
    let urlNoIdNoQuery = urlSplit[0].slice(-1) === '/' ? urlSplit[0].slice(0, -1) : urlSplit[0];
    let type = singularize(urlNoIdNoQuery.substr(urlNoIdNoQuery.lastIndexOf('/') + 1));

    return type;<commit_msg>identify correct types for dasherized models in URLs<commit_after>import { singularize, capitalize, camelize } from 'ember-cli-mirage/utils/inflector';
import _isArray from 'lodash/lang/isArray';

const allDigitsRegex = /^\d+$/;

export default class BaseShorthandRouteHandler {

  constructor(dbOrSchema, serializerOrRegistry, shorthand, options) {
    this.dbOrSchema = dbOrSchema;
    this.serializerOrRegistry = serializerOrRegistry;
    this.shorthand = shorthand;
    this.options = options;
  }

  handle(request) {
    let type = _isArray(this.shorthand) ? 'array' : typeof this.shorthand;
    let typeHandler = `handle${capitalize(type)}Shorthand`;

    return this[typeHandler](this.shorthand, this.dbOrSchema, request, this.options);
  }

  _getIdForRequest(request) {
    let id;

    if (request && request.params && request.params.id) {
      id = request.params.id;
      // If parses, coerce to integer
      if (typeof id === "string" && allDigitsRegex.test(id)) {
        id = parseInt(request.params.id, 10);
      }
    }

    return id;
  }

  _getUrlForRequest(request) {
    let url;

    if (request && request.url) {
      url = request.url;
    }

    return url;
  }

  _getTypeFromUrl(url, hasId) {
    let urlNoId = hasId ? url.substr(0, url.lastIndexOf('/')) : url;
    let urlSplit = urlNoId.split('?');
    let urlNoIdNoQuery = urlSplit[0].slice(-1) === '/' ? urlSplit[0].slice(0, -1) : urlSplit[0];
    let type = camelize(singularize(urlNoIdNoQuery.substr(urlNoIdNoQuery.lastIndexOf('/') + 1)));

    return type;
{'fraction_non_alphanumeric': 0.13727422003284073, 'fraction_numerical': 0.006568144499178982, 'mean_word_length': 3.453216374269006, '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': '3939053', 'n_tokens_mistral': 1055, 'n_tokens_neox': 1022, 'n_words': 208}