<commit_before>require_relative 'plugin/events'
#
# This middleware is the basis of all tracking via rack middleware.
#
# It allows you to easily create your own tracker and simply plugin it into Nark allowing you to gain
# valuable information on the service you are currently running.
#
module Nark
  class Middleware
    #
    # Keep trap of the event Handlers
    #
    # Also make it easier to handle our changes
    #
    attr_accessor :event_handler
    #
    # Set the application to an instance variable.
    #
    # This is needed to allow Rack to call our middleware simply by
    # use the module.
    #
    def initialize app, event_handler = Nark::Plugin
      @app = app
      @event_handler = event_handler
    end

    #
    # Call our middleware
    #
    # This is called by Rack when the Module is included in an application.
    #
    # This is where events are triggered if any are defined within a custom
    # plugin.
    #
    def call env
      event_handler.trigger :before_call, env
      status, header, body = @app.call env
      event_handler.trigger :after_call, [status, header, body, env]
      [status, header, body]
    end
  end
end<commit_msg>Create attribute accessor for the app variable<commit_after>require_relative 'plugin/events'
#
# This middleware is the basis of all tracking via rack middleware.
#
# It allows you to easily create your own tracker and simply plugin it into Nark allowing you to gain
# valuable information on the service you are currently running.
#
module Nark
  class Middleware
    #
    # Keep trap of the event Handlers
    #
    # Also make it easier to handle our changes
    #
    attr_accessor :event_handler

    #
    # Stores the application that the middle ware will call
    #
    attr_accessor :app

    #
    # Set the application to an instance variable.
    #
    # This is needed to allow Rack to call our middleware simply by
    # use the module.
    #
    def initialize app, event_handler = Nark::Plugin
      @app = app
      @event_handler = event_handler
    end

    #
    # Call our middleware
    #
    # This is called by Rack when the Module is included in an application.
    #
    # This is where events are triggered if any are defined within a custom
    # plugin.
    #
    def call env
      event_handler.trigger :before_call, env
      status, header, body = app.call env
      event_handler.trigger :after_call, [status, header, body, env]
      [status, header, body]
    end
  end
end
{'fraction_non_alphanumeric': 0.0541951023685267, 'fraction_numerical': 0.0, 'mean_word_length': 2.659324522760646, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1965183', 'n_tokens_mistral': 690, 'n_tokens_neox': 682, 'n_words': 308}