Class: YARD::Verifier
- Inherits:
-
Object
- Object
- YARD::Verifier
- Defined in:
- lib/yard/verifier.rb
Overview
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)
Constant Summary
Instance Attribute Summary (collapse)
-
- (Array<String>) expressions
A list of all expressions the verifier checks for.
-
- (CodeObjects::Base) object
(also: #o)
readonly
protected
The current object being tested.
Instance Method Summary (collapse)
-
- (void) add_expressions(*expressions)
Adds a set of expressions and recompiles the verifier.
-
- (Boolean) call(object)
Tests the expressions on the object.
-
- (Verifier) initialize(*expressions)
constructor
Creates a verifier from a set of expressions.
-
- (Object) method_missing(sym, *args, &block)
Passes any method calls to the object from the #call.
-
- (Array<CodeObjects::Base>) run(list)
Runs a list of objects against the verifier and returns the subset of verified objects.
Constructor Details
- (Verifier) initialize(*expressions)
Creates a verifier from a set of expressions
47 48 49 50 |
# File 'lib/yard/verifier.rb', line 47 def initialize(*expressions) @expressions = [] add_expressions(*expressions) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
- (Object) method_missing(sym, *args, &block)
Passes any method calls to the object from the #call
62 63 64 65 66 67 68 |
# File 'lib/yard/verifier.rb', line 62 def method_missing(sym, *args, &block) if object.respond_to?(sym) object.send(sym, *args, &block) else super end end |
Instance Attribute Details
- (Array<String>) expressions
Returns a list of all expressions the verifier checks for
36 37 38 |
# File 'lib/yard/verifier.rb', line 36 def expressions @expressions end |
- (CodeObjects::Base) object (readonly, protected) Also known as: o
Returns the current object being tested
97 98 99 |
# File 'lib/yard/verifier.rb', line 97 def object @object end |
Instance Method Details
- (void) add_expressions(*expressions)
This method returns an undefined value.
Adds a set of expressions and recompiles the verifier
57 58 59 |
# File 'lib/yard/verifier.rb', line 57 def add_expressions(*expressions) self.expressions += expressions.flatten end |
- (Boolean) call(object)
If the object is a CodeObjects::Proxy the result will always be true.
Tests the expressions on the object.
75 76 77 78 79 80 81 82 |
# File 'lib/yard/verifier.rb', line 75 def call(object) return true if object.is_a?(CodeObjects::Proxy) modify_nilclass @object = object retval = __execute ? true : false unmodify_nilclass retval end |
- (Array<CodeObjects::Base>) run(list)
Runs a list of objects against the verifier and returns the subset of verified objects.
90 91 92 |
# File 'lib/yard/verifier.rb', line 90 def run(list) list.reject {|item| call(item).is_a?(FalseClass) } end |