<commit_before>require 'capybara'

module Capybara
  class << self
    attr_writer :default_driver, :current_driver, :javascript_driver

    attr_accessor :app

    def default_driver
      @default_driver || :rack_test
    end

    def current_driver
      @current_driver || default_driver
    end
    alias_method :mode, :current_driver

    def javascript_driver
      @javascript_driver || :selenium
    end

    def use_default_driver
      @current_driver = nil
    end

    def current_session
      session_pool["#{current_driver}#{app.object_id}"] ||= Capybara::Session.new(current_driver, app)
    end

    def reset_sessions!
      session_pool.each { |mode, session| session.cleanup! }
      @session_pool = nil
    end

  private

    def session_pool
      @session_pool ||= {}
    end
  end

  extend(self)

  def page
    Capybara.current_session
  end

  Session::DSL_METHODS.each do |method|
    class_eval <<-RUBY, __FILE__, __LINE__+1
      def #{method}(*args, &block)
        page.#{method}(*args, &block)
      end
    RUBY
  end

end<commit_msg>Documentation for DSL<commit_after>require 'capybara'

module Capybara
  class << self
    attr_writer :default_driver, :current_driver, :javascript_driver

    attr_accessor :app

    ##
    #
    # @return [Symbol]    The name of the driver to use by default
    #
    def default_driver
      @default_driver || :rack_test
    end

    ##
    #
    # @return [Symbol]    The name of the driver currently in use
    #
    def current_driver
      @current_driver || default_driver
    end
    alias_method :mode, :current_driver

    ##
    #
    # @return [Symbol]    The name of the driver used when JavaScript is needed
    #
    def javascript_driver
      @javascript_driver || :selenium
    end

    ##
    #
    # Use the default driver as the current driver
    #
    def use_default_driver
      @current_driver = nil
    end

    ##
    #
    # The current Capybara::Session base on what is set as Capybara.app and Capybara.current_driver
    #
    # @return [Capybara::Session]     The currently used session
    #
    def current_session
      session_pool["#{current_driver}#{app.object_id}"] ||= Capybara::Session.new(current_driver, app)
    end

    ##
    #
    # Reset sessions, cleaning out the pool of sessions. This will remove any session information such
    # as cookies.
    #
    def reset_sessions!
      session_pool.each { |mode, session| session.cleanup! }
      @session_pool = nil
    end

  private

    def session_pool
      @session_pool ||= {}
    end
  end

  extend(self)

  ##
  #
  # Shortcut to accessing the current session. This is useful when Capybara is included in a
  # class or module.
  #
  #     class MyClass
  #       include Capybara
  #
  #       def has_header?
  #         page.has_css?('h1')
  #       end
  #     end
  #
  # @return [Capybara::Session] The current session object
  #
  def page
    Capybara.current_session
  end

  Session::DSL_METHODS.each do |method|
    class_eval <<-RUBY, __FILE__, __LINE__+1
      def #{method}(*args, &block)
        page.#{method}(*args, &block)
      end
    RUBY
  end

end
{'fraction_non_alphanumeric': 0.08828199428389966, 'fraction_numerical': 0.000952683391552874, 'mean_word_length': 2.531390134529148, 'pattern_counts': {'":': 0, '<': 11, '<?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': '5730803', 'n_tokens_mistral': 1025, 'n_tokens_neox': 992, 'n_words': 264}