Class: Aspect::Verifier::Check
- Inherits:
-
Object
- Object
- Aspect::Verifier::Check
- Extended by:
- HasRegistry
- Defined in:
- lib/aspect/verifier/check.rb
Overview
A single verification check.
To define a new check, you must first register it, then define an attribute for it on the Aspect::Verifier class.
If the check’s block returns a falsey value or raises an error, the check is considered failed. When a truthy value is return, the check has passed.
Class Method Summary collapse
-
.[](name) ⇒ Check
Get a registered ‘Check` instance by it’s name.
Instance Method Summary collapse
-
#block(&block) ⇒ Proc
Get or set the block for the check.
-
#block=(value) ⇒ Proc
Set the block for the check.
-
#call(value, expectation) ⇒ Boolean
Call the block.
-
#initialize(&block) ⇒ Check
constructor
A new instance of Check.
Methods included from HasRegistry
register, registered?, registry
Constructor Details
#initialize(&block) ⇒ Check
Returns a new instance of Check.
51 52 53 |
# File 'lib/aspect/verifier/check.rb', line 51 def initialize(&block) self.block = block end |
Class Method Details
.[](name) ⇒ Check
Get a registered ‘Check` instance by it’s name.
46 47 48 |
# File 'lib/aspect/verifier/check.rb', line 46 def [](name) registry[name.to_sym] end |
Instance Method Details
#block(&block) ⇒ Proc
Get or set the block for the check.
58 59 60 61 62 |
# File 'lib/aspect/verifier/check.rb', line 58 def block(&block) self.block = block if block_given? @block end |
#block=(value) ⇒ Proc
Set the block for the check.
68 69 70 71 72 73 74 75 76 |
# File 'lib/aspect/verifier/check.rb', line 68 def block=(value) if block_given? raise ArgumentError, "block must have 1 block argument" unless value.arity == 1 @block = value end @block end |
#call(value, expectation) ⇒ Boolean
Call the block.
82 83 84 |
# File 'lib/aspect/verifier/check.rb', line 82 def call(value, expectation) !!@block.call(value, expectation) rescue false end |