lib/yard/verifier.rb in yard-0.5.8 vs lib/yard/verifier.rb in yard-0.6.0

- old
+ new

@@ -30,10 +30,11 @@ # 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 + # @since 0.5.6 attr_reader :expressions def expressions=(value) @expressions = value create_method_from_expressions @@ -50,10 +51,11 @@ # Adds a set of expressions and recompiles the verifier # # @param [Array<String>] expressions a list of expressions # @return [void] + # @since 0.5.6 def add_expressions(*expressions) self.expressions += expressions.flatten end # Passes any method calls to the object from the {#call} @@ -75,31 +77,48 @@ retval = __execute ? true : false unmodify_nilclass retval end + # Runs a list of objects against the verifier and returns the subset + # of verified objects. + # + # @param [Array<CodeObjects::Base>] list a list of code objects + # @return [Array<CodeObjects::Base>] a list of code objects that match + # the verifier. + def run(list) + list.reject {|item| call(item).is_a?(FalseClass) } + 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.send(:define_method, :method_missing) {|*args| } + 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.send(:undef_method, :method_missing) + 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] \ No newline at end of file