Class: Hermod::Validators::TypeChecker
- Defined in:
- lib/hermod/validators/type_checker.rb
Overview
This checks if the given value is an instance of a certain class
Instance Attribute Summary collapse
-
#checker ⇒ Object
readonly
Returns the value of attribute checker.
-
#expected_class ⇒ Object
readonly
Returns the value of attribute expected_class.
Instance Method Summary collapse
-
#initialize(expected_class, &block) ⇒ TypeChecker
constructor
Sets up the validator with the class it is expected to be.
Methods inherited from Base
Constructor Details
#initialize(expected_class, &block) ⇒ TypeChecker
Sets up the validator with the class it is expected to be. You can optionally pass a block to customise the class matching logic
Examples
TypeChecker.new(Integer)
TypeChecker.new(Date) { |value| value.respond_to? :strftime }
19 20 21 22 |
# File 'lib/hermod/validators/type_checker.rb', line 19 def initialize(expected_class, &block) @expected_class = expected_class @checker = block || proc { |value| value.is_a? expected_class } end |
Instance Attribute Details
#checker ⇒ Object (readonly)
Returns the value of attribute checker.
8 9 10 |
# File 'lib/hermod/validators/type_checker.rb', line 8 def checker @checker end |
#expected_class ⇒ Object (readonly)
Returns the value of attribute expected_class.
8 9 10 |
# File 'lib/hermod/validators/type_checker.rb', line 8 def expected_class @expected_class end |