<commit_before>Rails.application.routes.draw do

  root to: 'application#index'

  # reusable regex
  number = /[-]?\d+/
  number_with_anchors = /\A[-]?\d+\z/

  get '/:op1/plus/:op2' => 'application#add', constraints: { :op1 => number, :op2 => number }
  get '/:op1/plus/:op2' => 'application#bad_request'

  get '/:op1/minus/:op2' => 'application#subtract', constraints: { :op1 => number, :op2 => number }
  get '/:op1/minus/:op2' => 'application#bad_request'

  get '/:op1/times/:op2' => 'application#multiply', constraints: { :op1 => number, :op2 => number }
  get '/:op1/times/:op2' => 'application#bad_request'

  get '/:op1/by/:op2' => 'application#divide', constraints: proc { |req| number_with_anchors === req.params[:op1] && number_with_anchors === req.params[:op2] && req.params[:op2].to_i != 0 }
  get '/:op1/by/:op2' => 'application#bad_request'

end
<commit_msg>Update routes to use procs as rack endpoints.<commit_after>Rails.application.routes.draw do

  root to: 'application#index'

  # reusable regex
  number = /[-]?\d+/
  number_with_anchors = /\A[-]?\d+\z/

  get '/:op1/plus/:op2' => 'application#add',
    constraints: { :op1 => number, :op2 => number },
    to: proc { |env| [200, {}, ["#{:op1.to_i + :op2.to_i}"]] }
  get '/:op1/plus/:op2' => 'application#bad_request'

  get '/:op1/minus/:op2' => 'application#subtract',
    constraints: { :op1 => number, :op2 => number },
    to: proc { |env| [200, {}, ["#{:op1.to_i - :op2.to_i}"]] }
  get '/:op1/minus/:op2' => 'application#bad_request'

  get '/:op1/times/:op2' => 'application#multiply',
    constraints: { :op1 => number, :op2 => number },
    to: proc { |env| [200, {}, ["#{:op1.to_i * :op2.to_i}"]] }
  get '/:op1/times/:op2' => 'application#bad_request'

  get '/:op1/by/:op2' => 'application#divide',
    constraints: proc { |req| number_with_anchors === req.params[:op1] && number_with_anchors === req.params[:op2] && req.params[:op2].to_i != 0 },
    to: proc { |env| [200, {}, ["#{:op1.to_i / :op2.to_i}"]] }
  get '/:op1/by/:op2' => 'application#bad_request'

end

{'fraction_non_alphanumeric': 0.23297665369649806, 'fraction_numerical': 0.03501945525291829, 'mean_word_length': 3.9566265060240964, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '757232', 'n_tokens_mistral': 832, 'n_tokens_neox': 824, 'n_words': 151}