<commit_before>class Redis
  module EM
    class Mutex
      # Macro-style definition
      #
      # idea and some code borrowed from http://github.com/kenn/redis-mutex and enhanced
      #
      # class ClassWithCriticalMethods
      #   include Redis::EM::Mutex::Macro
      #
      #   auto_mutex
      #   def critical
      #     ... do some critical stuff
      #     ....only one fiber in one process on one machine is executing this instance method of any instance of defined class
      #   end
      # end
      #
      module Macro
        def self.included(klass)
          klass.extend ClassMethods
          klass.class_eval do
            class << self
              attr_reader :auto_mutex_methods, :auto_mutex_options
              attr_accessor :auto_mutex_enabled
            end
            @auto_mutex_methods = {}
            @auto_mutex_options = {:ns => Redis::EM::Mutex.ns ? "#{Redis::EM::Mutex.ns}:#{klass.name}" : klass.name}
            @auto_mutex_enabled = false
          end
        end

        module ClassMethods
          # auto_mutex [*method_names], [options]
          #
          # options are:
          # - :expire - see Mutex.new
          # - :block  - see Mutex.new
          # - :ns     - custom namespace, normally name of a class that includes Macro is used
          # - :on_timeout - if defined, this proc will be called instead of raising MutexTimeout error
          #
          # If method_names are provided (already defined or defined in the future)
          # they become protected with mutex.
          #
          # If only options are provided, they become default for subsequent auto_mutex calls.
          #
          # If auto_mutex has no arguments then any further defined method will be protected.
          # To disable auto_mutex call no_auto_mutex.
          def auto_mutex(*args)
            options = args.last.kind_of?(Hash) ? args.pop : {}
            if args.each {|target|
                self.auto_mutex_methods[target] = self.auto_mutex_options.merge(options)
                auto_mutex_method_added(target) if method_defined? target
              }.empty?
              if options.empty?
                self.auto_mutex_enabled = true
              else
                self.auto_mutex_options.update(options)
              end
            end
          end

          # any subsequent methods won't be protected with mutex
          def no_auto_mutex
            self.auto_mutex_enabled = false
          end

          def method_added(target)
            return if target.to_s =~ /_(?:with|without|on_timeout)_auto_mutex$/
            return unless self.auto_mutex_methods[target] || self.auto_mutex_enabled
            auto_mutex_method_added(target)<commit_msg>docs update<commit_after>class Redis
  module EM
    class Mutex
      # Macro-style definition
      #
      # idea and some code borrowed from http://github.com/kenn/redis-mutex and enhanced
      #
      # class ClassWithCriticalMethods
      #   include Redis::EM::Mutex::Macro
      #
      #   auto_mutex
      #   def critical
      #     ... do some critical stuff
      #     ....only one fiber in one process on one machine is executing this instance method of any instance of defined class
      #   end
      # end
      #
      module Macro
        def self.included(klass)
          klass.extend ClassMethods
          klass.class_eval do
            class << self
              attr_reader :auto_mutex_methods, :auto_mutex_options
              attr_accessor :auto_mutex_enabled
            end
            @auto_mutex_methods = {}
            @auto_mutex_options = {:ns => Redis::EM::Mutex.ns ? "#{Redis::EM::Mutex.ns}:#{klass.name}" : klass.name}
            @auto_mutex_enabled = false
          end
        end

        module ClassMethods
          # auto_mutex [*method_names], [options]
          #
          # options are:
          # - :expire - see Mutex.new
          # - :block  - see Mutex.new
          # - :ns     - custom namespace, if not present name of the class that includes Macro is used
          # - :on_timeout - if defined, this proc/method will be called instead of raising MutexTimeout error
          #
          # If method_names are provided (names of already defined methods or defined in the future)
          # they become protected with mutex.
          #
          # If options are provided wihout method_names, they will become default options
          # for subsequent auto_mutex calls.
          #
          # If auto_mutex is called without arguments then any method further defined will also be protected.
          # To disable implicit auto_mutex use no_auto_mutex.
          def auto_mutex(*args)
            options = args.last.kind_of?(Hash) ? args.pop : {}
            if args.each {|target|
                self.auto_mutex_methods[target] = self.auto_mutex_options.merge(options)
                auto_mutex_method_added(target) if method_defined? target
              }.empty?
              if options.empty?
                self.auto_mutex_enabled = true
              else
                self.auto_mutex_options.update(options)
              end
            end
          end

          # Switch off implicit auto_mutex.
          # After calling no_auto_mutex if any new method is defined it won't be protected
          # unless explicitely specified with auto_mutex.
          def no_auto_mutex
            self.auto_mutex_enabled = false
          end

          def method_added(target)
            return if target.to_s =~ /_(?:with|without|on_timeout)_auto_mutex$/
            return unless self.auto_mutex_methods[target] || self.auto_mutex_enabled
            auto_mutex_method_added(target)
{'fraction_non_alphanumeric': 0.06967787114845939, 'fraction_numerical': 0.0, 'mean_word_length': 1.7881893606637385, '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': '1654360', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1474, 'n_words': 443}