<commit_before># coding: utf-8

require 'forwardable'
require 'stoplight/data_store'
require 'stoplight/data_store/base'
require 'stoplight/data_store/memory'
require 'stoplight/data_store/redis'
require 'stoplight/error'
require 'stoplight/failure'
require 'stoplight/light'

module Stoplight
  VERSION = Gem::Version.new('0.0.0')

  module_function

  def data_store(data_store = nil)
    @data_store = data_store if data_store
    @data_store = DataStore::Memory.new unless defined?(@data_store)
    @data_store
  end

  def green?(name)
    case data_store.state(name)
    when DataStore::STATE_LOCKED_GREEN
      true
    when DataStore::STATE_LOCKED_RED
      false
    else
      data_store.failures(name).size < threshold(name)
    end
  end

  def red?(name)
    !green?(name)
  end

  def threshold(name)
    data_store.failure_threshold(name) || Light::DEFAULT_FAILURE_THRESHOLD
  end

  class << self
    extend Forwardable

    def_delegators :data_store, *%i(
      clear_failures
      failure_threshold
      failures
      names
      record_attempt
      record_failure
      set_failure_threshold
      set_state
      state
    )
  end
end<commit_msg>Define module functions in class block<commit_after># coding: utf-8

require 'forwardable'
require 'stoplight/data_store'
require 'stoplight/data_store/base'
require 'stoplight/data_store/memory'
require 'stoplight/data_store/redis'
require 'stoplight/error'
require 'stoplight/failure'
require 'stoplight/light'

module Stoplight
  VERSION = Gem::Version.new('0.0.0')

  class << self
    extend Forwardable

    def_delegators :data_store, *%i(
      clear_failures
      failure_threshold
      failures
      names
      record_attempt
      record_failure
      set_failure_threshold
      set_state
      state
    )

    def data_store(data_store = nil)
      @data_store = data_store if data_store
      @data_store = DataStore::Memory.new unless defined?(@data_store)
      @data_store
    end

    def green?(name)
      case data_store.state(name)
      when DataStore::STATE_LOCKED_GREEN
        true
      when DataStore::STATE_LOCKED_RED
        false
      else
        data_store.failures(name).size < threshold(name)
      end
    end

    def red?(name)
      !green?(name)
    end

    def threshold(name)
      data_store.failure_threshold(name) || Light::DEFAULT_FAILURE_THRESHOLD
    end
  end
end
{'fraction_non_alphanumeric': 0.08200836820083682, 'fraction_numerical': 0.0033472803347280333, 'mean_word_length': 3.209507042253521, 'pattern_counts': {'":': 0, '<': 9, '<?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': '6048111', 'n_tokens_mistral': 771, 'n_tokens_neox': 762, 'n_words': 161}