<commit_before>module RspecApiDocumentation::DSL
  # DSL methods available at the example group level
  module Resource
    extend ActiveSupport::Concern

    module ClassMethods
      def self.define_action(method)
        define_method method do |*args, &block|
          options = if args.last.is_a?(Hash) then args.pop else {} end
          options[:method] = method
          options[:route] = args.first
          options[:api_doc_dsl] = :endpoint
          args.push(options)
          args[0] = "#{method.to_s.upcase} #{args[0]}"
          context(*args, &block)
        end
      end

      define_action :get
      define_action :post
      define_action :put
      define_action :delete
      define_action :head
      define_action :patch

      def callback(*args, &block)
        begin
          require 'webmock'
        rescue LoadError
          raise "Callbacks require webmock to be installed"
        end
        self.send(:include, WebMock::API)

        options = if args.last.is_a?(Hash) then args.pop else {} end
        options[:api_doc_dsl] = :callback
        args.push(options)

        context(*args, &block)
      end

      def parameter(name, description, options = {})
        parameters.push(options.merge(:name => name.to_s, :description => description))
      end

      def response_field(name, description, options = {})
        response_fields.push(options.merge(:name => name.to_s, :description => description))
      end

      def header(name, value)
        headers[name] = value
      end

      private
      def parameters
        metadata[:parameters] ||= []
        if superclass_metadata && metadata[:parameters].equal?(superclass_metadata[:parameters])
          metadata[:parameters] = Marshal.load(Marshal.dump(superclass_metadata[:parameters]))
        end
        metadata[:parameters]
      end

      def response_fields
        metadata[:response_fields] ||= []
        if superclass_metadata && metadata[:response_fields].equal?(superclass_metadata[:response_fields])
          metadata[:response_fields] = Marshal.load(Marshal.dump(superclass_metadata[:response_fields]))
        end
        metadata[:response_fields]
      end

      def headers
        metadata[:headers] ||= {}
        if superclass_metadata && metadata[:headers].equal?(superclass_metadata[:headers])
          metadata[:headers] = Marshal.load(Marshal.dump(superclass_metadata[:headers]))
        end
        metadata[:headers]<commit_msg>Move superclass_metadata checking into a single method<commit_after>module RspecApiDocumentation::DSL
  # DSL methods available at the example group level
  module Resource
    extend ActiveSupport::Concern

    module ClassMethods
      def self.define_action(method)
        define_method method do |*args, &block|
          options = if args.last.is_a?(Hash) then args.pop else {} end
          options[:method] = method
          options[:route] = args.first
          options[:api_doc_dsl] = :endpoint
          args.push(options)
          args[0] = "#{method.to_s.upcase} #{args[0]}"
          context(*args, &block)
        end
      end

      define_action :get
      define_action :post
      define_action :put
      define_action :delete
      define_action :head
      define_action :patch

      def callback(*args, &block)
        begin
          require 'webmock'
        rescue LoadError
          raise "Callbacks require webmock to be installed"
        end
        self.send(:include, WebMock::API)

        options = if args.last.is_a?(Hash) then args.pop else {} end
        options[:api_doc_dsl] = :callback
        args.push(options)

        context(*args, &block)
      end

      def parameter(name, description, options = {})
        parameters.push(options.merge(:name => name.to_s, :description => description))
      end

      def response_field(name, description, options = {})
        response_fields.push(options.merge(:name => name.to_s, :description => description))
      end

      def header(name, value)
        headers[name] = value
      end

      private

      def safe_metadata(field, default)
        metadata[field] ||= default
        if superclass_metadata && metadata[field].equal?(superclass_metadata[field])
          metadata[field] = Marshal.load(Marshal.dump(superclass_metadata[field]))
        end
        metadata[field]
      end

      def parameters
        safe_metadata(:parameters, [])
      end

      def response_fields
        safe_metadata(:response_fields, [])
      end

      def headers
        safe_metadata(:headers, {})
{'fraction_non_alphanumeric': 0.10177281680892974, 'fraction_numerical': 0.0008754650908295032, 'mean_word_length': 2.528957528957529, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '966650', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1218, 'n_words': 285}