Class: AWS::Record::Validator
- Inherits:
-
Object
- Object
- AWS::Record::Validator
- Defined in:
- lib/aws/record/validator.rb
Overview
Base class for all validators
Direct Known Subclasses
AcceptanceValidator, BlockValidator, ConfirmationValidator, CountValidator, FormatValidator, InclusionValidator, LengthValidator, MethodValidator, NumericalityValidator, PresenceValidator
Constant Summary collapse
- ACCEPTED_OPTIONS =
these should be defined in subclasses
[]
Instance Attribute Summary collapse
-
#attribute_names ⇒ String
readonly
Returns the name of the attribute this validator will check on the record during validation.
-
#options ⇒ Hash
readonly
Returns the hash of options for this validator.
Instance Method Summary collapse
-
#initialize(record_class, *attribute_names, &block) ⇒ Validator
constructor
A new instance of Validator.
- #validate(record) ⇒ Object
Constructor Details
#initialize(record_class, *attribute_names, &block) ⇒ Validator
Returns a new instance of Validator.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/aws/record/validator.rb', line 24 def initialize record_class, *attribute_names, &block @options = attribute_names.last.is_a?(Hash) ? attribute_names.pop : {} @attribute_names = attribute_names ensure_type([Symbol, Proc], :if, :unless) ensure_is([:save, :create, :update], :on) setup(record_class) end |
Instance Attribute Details
#attribute_names ⇒ String (readonly)
Returns the name of the attribute this validator will check on the record during validation.
41 42 43 |
# File 'lib/aws/record/validator.rb', line 41 def attribute_names @attribute_names end |
#options ⇒ Hash (readonly)
Returns the hash of options for this validator.
44 45 46 |
# File 'lib/aws/record/validator.rb', line 44 def @options end |
Instance Method Details
#validate(record) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/aws/record/validator.rb', line 46 def validate record if passes_on_condition?(record) and passes_if_condition?(record) and passes_unless_condition?(record) then validate_attributes(record) end end |