<commit_before>const CONFIG = require('config')
const __ = CONFIG.universalPath
const _ = __.require('lib', 'utils')
const contextsList = [ 'place' ]
const buildController = require('./build_controller')

module.exports = {
  generateRoutes: function () {
    const routes = {}
    contextsList.forEach(function (contextName) {
      _.extend(routes, contextRoutes(contextName))
    })
    return routes
  }
}

const contextRoutes = function (contextName) {
  const controller = buildController(contextName)
  const routes = {}
  routes[contextName] = {
    post: controller.post
  }
  routes[`${contextName}/:id`] = {
    get: controller.get
  }
  return routes
}<commit_msg>inducing the contextsList from available models<commit_after>const CONFIG = require('config')
const __ = CONFIG.universalPath
const _ = __.require('lib', 'utils')
const buildController = require('./build_controller')

// generating the list of contexts names from the files
// available in the models/contexts folder
const extractName = (filename) => filename.split('.')[0]
const folder = __.path('controllers', 'things/models/contexts')
const contextsList = require('fs').readdirSync(folder).map(extractName)

_.log(contextsList, 'contexts')

module.exports = {
  generateRoutes: function () {
    const routes = {}
    contextsList.forEach(function (contextName) {
      _.extend(routes, contextRoutes(contextName))
    })
    return routes
  }
}

const contextRoutes = function (contextName) {
  const controller = buildController(contextName)
  const routes = {}

  routes[contextName] = {
    post: controller.post
  }
  routes[`${contextName}/:id`] = {
    get: controller.get
  }

  return routes
}
{'fraction_non_alphanumeric': 0.1290898274836407, 'fraction_numerical': 0.000594883997620464, 'mean_word_length': 4.356687898089172, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '4721226', 'n_tokens_mistral': 497, 'n_tokens_neox': 491, 'n_words': 113}