<commit_before>require "singleton"

module Teaspoon
  autoload :Formatters, "teaspoon/formatters/base"
  autoload :Drivers,    "teaspoon/drivers/base"

  class Configuration
    include Singleton

    # CONTRIBUTORS:
    # If you add a configuration option you should do the following before it will be considered for merging.
    # - think about if it should be a suite, coverage, or global configuration
    # - write specs for it, and add it to existing specs in spec/teaspoon/configuration_spec.rb
    # - add it to the readme so it's documented
    # - add it to the command_line.rb if appropriate (_only_ if it's appropriate)
    # - add it to ENV_OVERRIDES if it can be overridden from ENV
    # - add it to the initializers in /lib/generators/install/templates so it's documented there as well

    cattr_accessor :mount_at, :root, :asset_paths, :fixture_paths
    @@mount_at       = "/teaspoon"
    @@root           = nil # will default to Rails.root
    @@asset_paths    = ["spec/javascripts", "spec/javascripts/stylesheets", "test/javascripts", "test/javascripts/stylesheets"]
    @@fixture_paths  = ["spec/javascripts/fixtures", "test/javascripts/fixtures"]

    # console runner specific

    cattr_accessor :driver, :driver_options, :driver_timeout, :server, :server_port, :server_timeout, :fail_fast,
                   :formatters, :color, :suppress_log,
                   :use_coverage
    @@driver         = "phantomjs"
    @@driver_options = nil
    @@driver_timeout = 180
    @@server         = nil
    @@server_port    = nil
    @@server_timeout = 20
    @@fail_fast      = true

    @@formatters     = ["dot"]
    @@color          = true
    @@suppress_log   = false

    @@use_coverage   = nil

    # options that can be specified in the ENV

    ENV_OVERRIDES = {
      boolean: %w(FAIL_FAST SUPPRESS_LOG COLOR),
      integer: %w(DRIVER_TIMEOUT SERVER_TIMEOUT),
      string:  %w(DRIVER DRIVER_OPTIONS SERVER SERVER_PORT FORMATTERS USE_COVERAGE)
    }

    # suite configurations

    cattr_accessor :suite_configs
    @@suite_configs = { "default" => { block: proc {} } }

    def self.suite(name = :default, &block)
      @@suite_configs[name.to_s] = { block: block, instance: Suite.new(&block) }
    end

    class Suite
      FRAMEWORKS = {
        jasmine: ["1.3.1", "2.0.0"],
        mocha: ["1.10.0", "1.17.1"],
        qunit: ["1.12.0", "1.14.0"],
      }

      attr_accessor   :matcher, :helper, :javascripts, :stylesheets,
                      :boot_partial, :body_partial, :no_coverage, :hooks,
                      :expand_assets

      def initialize
        @matcher       = "{spec/javascripts,app/assets}/**/*_spec.{js,js.coffee,coffee}"
        @helper        = "spec_helper"
        @javascripts   = ["jasmine/1.3.1", "teaspoon-jasmine"]
        @stylesheets   = ["teaspoon"]

        @boot_partial  = "boot"
        @body_partial  = "body"

        @no_coverage   = [%r{/lib/ruby/gems/}, %r{/vendor/assets/}, %r{/support/}, %r{/(.+)_helper.}]

        @hooks         = Hash.new { |h, k| h[k] = [] }
        @expand_assets = true

        default = Teaspoon.configuration.suite_configs["default"]
        instance_eval(&default[:block]) if default
        yield self if block_given?
      end

      def use_framework(name, version = nil)
        name = name.to_sym
        version ||= FRAMEWORKS[name].last if FRAMEWORKS[name]
        unless FRAMEWORKS[name] && FRAMEWORKS[name].include?(version)
          message = "Unknown framework \"#{name}\""
          if FRAMEWORKS[name] && version
            message += " with version #{version} -- available versions #{FRAMEWORKS[name].join(', ')}"
          end
          raise Teaspoon::UnknownFramework, message
        end

        @javascripts = [[name, version].join("/"), "teaspoon-#{name}"]
        case name.to_sym
        when :qunit
          @matcher = "{test/javascripts,app/assets}/**/*_test.{js,js.coffee,coffee}"
          @helper  = "test_helper"
        end
      end
      alias_method :use_framework=, :use_framework

      def hook(group = :default, &block)
        @hooks[group.to_s] << block<commit_msg>Adjust indentation<commit_after>require "singleton"

module Teaspoon
  autoload :Formatters, "teaspoon/formatters/base"
  autoload :Drivers,    "teaspoon/drivers/base"

  class Configuration
    include Singleton

    # CONTRIBUTORS:
    # If you add a configuration option you should do the following before it will be considered for merging.
    # - think about if it should be a suite, coverage, or global configuration
    # - write specs for it, and add it to existing specs in spec/teaspoon/configuration_spec.rb
    # - add it to the readme so it's documented
    # - add it to the command_line.rb if appropriate (_only_ if it's appropriate)
    # - add it to ENV_OVERRIDES if it can be overridden from ENV
    # - add it to the initializers in /lib/generators/install/templates so it's documented there as well

    cattr_accessor :mount_at, :root, :asset_paths, :fixture_paths
    @@mount_at       = "/teaspoon"
    @@root           = nil # will default to Rails.root
    @@asset_paths    = ["spec/javascripts", "spec/javascripts/stylesheets", "test/javascripts", "test/javascripts/stylesheets"]
    @@fixture_paths  = ["spec/javascripts/fixtures", "test/javascripts/fixtures"]

    # console runner specific

    cattr_accessor :driver, :driver_options, :driver_timeout, :server, :server_port, :server_timeout, :fail_fast,
                   :formatters, :color, :suppress_log,
                   :use_coverage
    @@driver         = "phantomjs"
    @@driver_options = nil
    @@driver_timeout = 180
    @@server         = nil
    @@server_port    = nil
    @@server_timeout = 20
    @@fail_fast      = true

    @@formatters     = ["dot"]
    @@color          = true
    @@suppress_log   = false

    @@use_coverage   = nil

    # options that can be specified in the ENV

    ENV_OVERRIDES = {
      boolean: %w(FAIL_FAST SUPPRESS_LOG COLOR),
      integer: %w(DRIVER_TIMEOUT SERVER_TIMEOUT),
      string:  %w(DRIVER DRIVER_OPTIONS SERVER SERVER_PORT FORMATTERS USE_COVERAGE)
    }

    # suite configurations

    cattr_accessor :suite_configs
    @@suite_configs = { "default" => { block: proc {} } }

    def self.suite(name = :default, &block)
      @@suite_configs[name.to_s] = { block: block, instance: Suite.new(&block) }
    end

    class Suite
      FRAMEWORKS = {
        jasmine: ["1.3.1", "2.0.0"],
        mocha: ["1.10.0", "1.17.1"],
        qunit: ["1.12.0", "1.14.0"],
      }

      attr_accessor :matcher, :helper, :javascripts, :stylesheets,
                    :boot_partial, :body_partial,
                    :no_coverage, :hooks, :expand_assets

      def initialize
        @matcher       = "{spec/javascripts,app/assets}/**/*_spec.{js,js.coffee,coffee}"
        @helper        = "spec_helper"
        @javascripts   = ["jasmine/1.3.1", "teaspoon-jasmine"]
        @stylesheets   = ["teaspoon"]

        @boot_partial  = "boot"
        @body_partial  = "body"

        @no_coverage   = [%r{/lib/ruby/gems/}, %r{/vendor/assets/}, %r{/support/}, %r{/(.+)_helper.}]
        @hooks         = Hash.new { |h, k| h[k] = [] }
        @expand_assets = true

        default = Teaspoon.configuration.suite_configs["default"]
        instance_eval(&default[:block]) if default
        yield self if block_given?
      end

      def use_framework(name, version = nil)
        name = name.to_sym
        version ||= FRAMEWORKS[name].last if FRAMEWORKS[name]
        unless FRAMEWORKS[name] && FRAMEWORKS[name].include?(version)
          message = "Unknown framework \"#{name}\""
          if FRAMEWORKS[name] && version
            message += " with version #{version} -- available versions #{FRAMEWORKS[name].join(', ')}"
          end
          raise Teaspoon::UnknownFramework, message
        end

        @javascripts = [[name, version].join("/"), "teaspoon-#{name}"]
        case name.to_sym
        when :qunit
          @matcher = "{test/javascripts,app/assets}/**/*_test.{js,js.coffee,coffee}"
          @helper  = "test_helper"
        end
      end
      alias_method :use_framework=, :use_framework

      def hook(group = :default, &block)
        @hooks[group.to_s] << block
{'fraction_non_alphanumeric': 0.12536443148688048, 'fraction_numerical': 0.007288629737609329, 'mean_word_length': 2.5108742004264393, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '4486222', 'n_tokens_mistral': 2749, 'n_tokens_neox': 2583, 'n_words': 626}