<commit_before>module GrapeMarkdown
  class Route < SimpleDelegator
    # would like to rely on SimpleDelegator but Grape::Route uses
    # method_missing for these methods :'(
    delegate :route_namespace,
             :route_path,
             :route_method,
             :route_description,
             to: '__getobj__'

    def route_params
      @route_params ||= __getobj__.route_params.sort.map do |param|
        Parameter.new(self, *param)
      end
    end

    def route_name
      route_namespace.split('/').last ||
        route_path.match('\/(\w*?)[\.\/\(]').captures.first
    end

    def route_path_without_format
      route_path.gsub(/\((.*?)\)/, '')
    end

    def route_model
      route_namespace.split('/').last.singularize
    end

    def route_type
      list? ? 'collection' : 'single'
    end

    def request_description
      "+ Request #{'(application/json)' if request_body?}"
    end

    def response_description
      code = route_method == 'POST' ? 201 : 200

      "+ Response #{code} (application/json)"
    end

    def list?
      %w(GET POST).include?(route_method) && !route_path.include?(':id')
    end

    private

    def request_body?
      !%w(GET DELETE).include?(route_method)
    end
  end
end
<commit_msg>Exposes binding for route class<commit_after>module GrapeMarkdown
  class Route < SimpleDelegator
    # would like to rely on SimpleDelegator but Grape::Route uses
    # method_missing for these methods :'(
    delegate :route_namespace,
             :route_path,
             :route_method,
             :route_description,
             to: '__getobj__'

    def route_params
      @route_params ||= __getobj__.route_params.sort.map do |param|
        Parameter.new(self, *param)
      end
    end

    def route_name
      route_namespace.split('/').last ||
        route_path.match('\/(\w*?)[\.\/\(]').captures.first
    end

    def route_path_without_format
      route_path.gsub(/\((.*?)\)/, '')
    end

    def route_model
      route_namespace.split('/').last.singularize
    end

    def route_type
      list? ? 'collection' : 'single'
    end

    def request_description
      "+ Request #{'(application/json)' if request_body?}"
    end

    def response_description
      code = route_method == 'POST' ? 201 : 200

      "+ Response #{code} (application/json)"
    end

    def list?
      %w(GET POST).include?(route_method) && !route_path.include?(':id')
    end

    def route_binding
      binding
    end

    private

    def request_body?
      !%w(GET DELETE).include?(route_method)
    end
  end
end

{'fraction_non_alphanumeric': 0.11914893617021277, 'fraction_numerical': 0.0046421663442940036, 'mean_word_length': 2.3671875, 'pattern_counts': {'":': 0, '<': 5, '<?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': '4122225', 'n_tokens_mistral': 829, 'n_tokens_neox': 785, 'n_words': 180}