<commit_before>module Sinatra
  module Schema
    class Link
      attr_accessor :resource, :title, :description, :href, :method, :rel, :action

      def initialize(options)
        @resource = options[:resource]
        @method   = options[:method]
        @href     = options[:href]
      end

      def action(&blk)
        @action = blk
      end

      def action_block
        @action
      end

      def register(app)
        link = self
        app.send(method.downcase, href) do
          res = link.action_block.call
          link.resource.validate_response!(res)
          link.resource.serialize(res)
        end
      end
    end

    class Definition
      attr_accessor :description, :example, :format, :type
    end

    class Resource
      attr_accessor :id, :path, :title, :description, :properties, :serializer

      def initialize(app, path)
        @app   = app
        @path  = path.chomp("/")
        @links = []
        @defs  = {}
      end

      def define(id)
        @defs[id] = Definition.new
        yield @defs[id]
      end

      def link(method, href, &blk)
        href = "#{path}/#{href.chomp("/")}".chomp("/")
        puts href
        link = Link.new(resource: self, method: method, href: href)
        yield(link)
        link.register(@app)
        @links << link
      end

      def validate_response!(res)<commit_msg>remove debug<commit_after>module Sinatra
  module Schema
    class Link
      attr_accessor :resource, :title, :description, :href, :method, :rel, :action

      def initialize(options)
        @resource = options[:resource]
        @method   = options[:method]
        @href     = options[:href]
      end

      def action(&blk)
        @action = blk
      end

      def action_block
        @action
      end

      def register(app)
        link = self
        app.send(method.downcase, href) do
          res = link.action_block.call
          link.resource.validate_response!(res)
          link.resource.serialize(res)
        end
      end
    end

    class Definition
      attr_accessor :description, :example, :format, :type
    end

    class Resource
      attr_accessor :id, :path, :title, :description, :properties, :serializer

      def initialize(app, path)
        @app   = app
        @path  = path.chomp("/")
        @links = []
        @defs  = {}
      end

      def define(id)
        @defs[id] = Definition.new
        yield @defs[id]
      end

      def link(method, href, &blk)
        href = "#{path}/#{href.chomp("/")}".chomp("/")
        link = Link.new(resource: self, method: method, href: href)
        yield(link)
        link.register(@app)
        @links << link
      end

      def validate_response!(res)
{'fraction_non_alphanumeric': 0.11500184297825286, 'fraction_numerical': 0.0, 'mean_word_length': 1.881104033970276, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1510648', 'n_tokens_mistral': 816, 'n_tokens_neox': 797, 'n_words': 202}