<commit_before>module YARD
  # Similar to a Proc, but runs a set of Ruby expressions using a small
  # DSL to make tag lookups easier.
  # 
  # The syntax is as follows:
  # * All syntax is Ruby compatible
  # * +object+ (+o+ for short) exist to access the object being verified
  # * +@TAGNAME+ is translated into +object.tag('TAGNAME')+
  # * +@@TAGNAME+ is translated into +object.tags('TAGNAME')+
  # * +object+ can be omitted as target for method calls (it is implied)
  # 
  # @example Create a verifier to check for objects that don't have @private tags
  #   verifier = Verifier.new('!@private')
  #   verifier.call(object) # => true (no @private tag)
  # @example Create a verifier to find any return tag with an empty description
  #   Verifier.new('@return.text.empty?')
  #   # Equivalent to:
  #   Verifier.new('object.tag(:return).text.empty?')
  # @example Check if there are any @param tags
  #   Verifier.new('@@param.empty?')
  #   # Equivalent to:
  #   Verifier.new('object.tags(:param).empty?')
  # @example Using +object+ or +o+ to look up object attributes directly
  #   Verifier.new('object.docstring == "hello world"')
  #   # Equivalent to:
  #   Verifier.new('o.docstring == "hello world"')
  # @example Without using +object+ or +o+
  #   Verifier.new('tag(:return).size == 1 || has_tag?(:author)')
  # @example Specifying multiple expressions
  #   Verifier.new('@return', '@param', '@yield')
  #   # Equivalent to:
  #   Verifier.new('@return && @param && @yield')
  class Verifier
    # @return [Array<String>] a list of all expressions the verifier checks for
    attr_reader :expressions
    
    def expressions=(value)
      @expressions = value
      create_method_from_expressions
    end
    
    # Creates a verifier from a set of expressions
    # 
    # @param [Array<String>] expressions a list of Ruby expressions to
    #   parse.
    def initialize(*expressions)
      @expressions = []
      add_expressions(*expressions)
    end
    
    # Adds a set of expressions and recompiles the verifier
    # 
    # @param [Array<String>] expressions a list of expressions
    # @return [void]
    def add_expressions(*expressions)
      self.expressions += expressions.flatten
    end
    
    # Passes any method calls to the object from the {#call}
    def method_missing(sym, *args, &block)
      if object.respond_to?(sym)
        object.send(sym, *args, &block)
      else
        super
      end
    end

    # Tests the expressions on the object
    # 
    # @param [CodeObjects::Base] object the object to verify
    # @return [Boolean] the result of the expressions
    def call(object)
      modify_nilclass
      @object = object
      retval = __execute ? true : false
      unmodify_nilclass
      retval
    end
    
    protected
    
    # @return [CodeObjects::Base] the current object being tested
    attr_reader :object
    alias o object
    
    private
    
    # Modifies nil to not throw NoMethodErrors. This allows
    # syntax like object.tag(:return).text to work if the #tag
    # call returns nil, which means users don't need to perform
    # stringent nil checking
    # 
    # @return [void] 
    def modify_nilclass
      NilClass.send(:define_method, :method_missing) {|*args| }
    end
    
    # Returns the state of NilClass back to normal
    # @return [void] 
    def unmodify_nilclass
      NilClass.send(:undef_method, :method_missing)
    end
    
    # Creates the +__execute+ method by evaluating the expressions
    # as Ruby code
    # @return [void] 
    def create_method_from_expressions<commit_msg>Fix Object#type deprecated warning in 1.8 for Verifier<commit_after>module YARD
  # Similar to a Proc, but runs a set of Ruby expressions using a small
  # DSL to make tag lookups easier.
  # 
  # The syntax is as follows:
  # * All syntax is Ruby compatible
  # * +object+ (+o+ for short) exist to access the object being verified
  # * +@TAGNAME+ is translated into +object.tag('TAGNAME')+
  # * +@@TAGNAME+ is translated into +object.tags('TAGNAME')+
  # * +object+ can be omitted as target for method calls (it is implied)
  # 
  # @example Create a verifier to check for objects that don't have @private tags
  #   verifier = Verifier.new('!@private')
  #   verifier.call(object) # => true (no @private tag)
  # @example Create a verifier to find any return tag with an empty description
  #   Verifier.new('@return.text.empty?')
  #   # Equivalent to:
  #   Verifier.new('object.tag(:return).text.empty?')
  # @example Check if there are any @param tags
  #   Verifier.new('@@param.empty?')
  #   # Equivalent to:
  #   Verifier.new('object.tags(:param).empty?')
  # @example Using +object+ or +o+ to look up object attributes directly
  #   Verifier.new('object.docstring == "hello world"')
  #   # Equivalent to:
  #   Verifier.new('o.docstring == "hello world"')
  # @example Without using +object+ or +o+
  #   Verifier.new('tag(:return).size == 1 || has_tag?(:author)')
  # @example Specifying multiple expressions
  #   Verifier.new('@return', '@param', '@yield')
  #   # Equivalent to:
  #   Verifier.new('@return && @param && @yield')
  class Verifier
    # @return [Array<String>] a list of all expressions the verifier checks for
    attr_reader :expressions
    
    def expressions=(value)
      @expressions = value
      create_method_from_expressions
    end
    
    # Creates a verifier from a set of expressions
    # 
    # @param [Array<String>] expressions a list of Ruby expressions to
    #   parse.
    def initialize(*expressions)
      @expressions = []
      add_expressions(*expressions)
    end
    
    # Adds a set of expressions and recompiles the verifier
    # 
    # @param [Array<String>] expressions a list of expressions
    # @return [void]
    def add_expressions(*expressions)
      self.expressions += expressions.flatten
    end
    
    # Passes any method calls to the object from the {#call}
    def method_missing(sym, *args, &block)
      if object.respond_to?(sym)
        object.send(sym, *args, &block)
      else
        super
      end
    end

    # Tests the expressions on the object
    # 
    # @param [CodeObjects::Base] object the object to verify
    # @return [Boolean] the result of the expressions
    def call(object)
      modify_nilclass
      @object = object
      retval = __execute ? true : false
      unmodify_nilclass
      retval
    end
    
    protected
    
    # @return [CodeObjects::Base] the current object being tested
    attr_reader :object
    alias o object
    
    private
    
    # @private
    NILCLASS_METHODS = [:type, :method_missing]
    
    # Modifies nil to not throw NoMethodErrors. This allows
    # syntax like object.tag(:return).text to work if the #tag
    # call returns nil, which means users don't need to perform
    # stringent nil checking
    # 
    # @return [void] 
    def modify_nilclass
      NILCLASS_METHODS.each do |meth|
        NilClass.send(:define_method, meth) {|*args| }
      end
    end
    
    # Returns the state of NilClass back to normal
    # @return [void] 
    def unmodify_nilclass
      NILCLASS_METHODS.each do |meth|
        NilClass.send(:undef_method, meth)
      end
    end
    
    # Creates the +__execute+ method by evaluating the expressions
    # as Ruby code
    # @return [void] 
    def create_method_from_expressions
{'fraction_non_alphanumeric': 0.1010183299389002, 'fraction_numerical': 0.0005431093007467753, 'mean_word_length': 2.860587002096436, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '1417172', 'n_tokens_mistral': 2250, 'n_tokens_neox': 2195, 'n_words': 732}