Class: SmartCore::Types::Primitive::Validator Private
- Inherits:
-
Object
- Object
- SmartCore::Types::Primitive::Validator
- Defined in:
- lib/smart_core/types/primitive/validator.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: Result
Instance Attribute Summary collapse
- #invariant_control ⇒ SmartCore::Types::Primitive::InvariantControl readonly private
- #type ⇒ SmartCore::Type::Primitive readonly private
- #type_checker ⇒ SmartCore::Types::Primitive::Checker readonly private
Instance Method Summary collapse
- #___assign_type___(type) ⇒ void private
- #___copy_for___(type) ⇒ SmartCore::Types::Primitive::Validator private
- #initialize(type_checker, invariant_control) ⇒ void constructor private
- #valid?(value) ⇒ Boolean private
- #validate(value) ⇒ SmartCore::Types::Primitive::Validator::Result private
- #validate!(value) ⇒ void private
Constructor Details
#initialize(type_checker, invariant_control) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
33 34 35 36 37 |
# File 'lib/smart_core/types/primitive/validator.rb', line 33 def initialize(type_checker, invariant_control) @type = nil @type_checker = type_checker @invariant_control = invariant_control end |
Instance Attribute Details
#invariant_control ⇒ SmartCore::Types::Primitive::InvariantControl (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
25 26 27 |
# File 'lib/smart_core/types/primitive/validator.rb', line 25 def invariant_control @invariant_control end |
#type ⇒ SmartCore::Type::Primitive (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
13 14 15 |
# File 'lib/smart_core/types/primitive/validator.rb', line 13 def type @type end |
#type_checker ⇒ SmartCore::Types::Primitive::Checker (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
19 20 21 |
# File 'lib/smart_core/types/primitive/validator.rb', line 19 def type_checker @type_checker end |
Instance Method Details
#___assign_type___(type) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
55 56 57 |
# File 'lib/smart_core/types/primitive/validator.rb', line 55 def ___assign_type___(type) @type = type end |
#___copy_for___(type) ⇒ SmartCore::Types::Primitive::Validator
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
44 45 46 47 48 |
# File 'lib/smart_core/types/primitive/validator.rb', line 44 def ___copy_for___(type) self.class.new(type_checker, invariant_control).tap do |instance_copy| instance_copy.___assign_type___(type) end end |
#valid?(value) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
64 65 66 |
# File 'lib/smart_core/types/primitive/validator.rb', line 64 def valid?(value) validate(value).success? end |
#validate(value) ⇒ SmartCore::Types::Primitive::Validator::Result
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
74 75 76 77 78 79 80 |
# File 'lib/smart_core/types/primitive/validator.rb', line 74 def validate(value) checker_result = type_checker.call(value, type.runtime_attributes) # => Boolean return Result.new(type, value, checker_result) unless checker_result invariant_result = invariant_control.check(value, type.runtime_attributes) invariant_errors = invariant_result.invariant_errors.map { |error| "#{type.name}.#{error}" } Result.new(type, value, checker_result, invariant_errors) end |
#validate!(value) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
89 90 91 92 |
# File 'lib/smart_core/types/primitive/validator.rb', line 89 def validate!(value) return if validate(value).success? raise(SmartCore::Types::TypeError, 'Invalid type') end |