<commit_before>module JsonApiRoutes
  def id_constraint(path)
    { :"#{ path.to_s.singularize }_id" => /[0-9]*/ }
  end
  
  def create_links(path, links)
    links_regex = /(#{ links.map(&:to_s).join('|') })/
    constraints = { link_relation: links_regex }.merge(id_constraint(path))
    
    post "/links/:link_relation", to: "#{ path }#update_links",
      constraints: constraints, format: :false
    
    delete "/links/:link_relation/:link_ids", to: "#{ path }#update_links",
      constraints: constraints, format: :false
  end
  
  def json_api_resources(path, options={})
    links = options.delete(:links)
    options = options.merge(except: [:new, :edit],
                            constraints: { id: /[0-9]*/ },
                            format: false)<commit_msg>Extract id regex to constant<commit_after>module JsonApiRoutes
  VALID_IDS = /[0-9]*/
  
  def id_constraint(path)
    { :"#{ path.to_s.singularize }_id" => VALID_IDS }
  end
  
  def create_links(path, links)
    links_regex = /(#{ links.map(&:to_s).join('|') })/
    constraints = { link_relation: links_regex }.merge(id_constraint(path))
    
    post "/links/:link_relation", to: "#{ path }#update_links",
      constraints: constraints, format: :false
    
    delete "/links/:link_relation/:link_ids", to: "#{ path }#update_links",
      constraints: constraints, format: :false
  end
  
  def json_api_resources(path, options={})
    links = options.delete(:links)
    options = options.merge(except: [:new, :edit],
                            constraints: { id: VALID_IDS },
                            format: false)
{'fraction_non_alphanumeric': 0.1537025513378967, 'fraction_numerical': 0.00373366521468575, 'mean_word_length': 2.81042654028436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7423758', 'n_tokens_mistral': 517, 'n_tokens_neox': 527, 'n_words': 105}