module AWS::Record::Validations
def self.extended base
def self.extended base base.send(:define_method, :run_validations) do errors.clear! self.class.send(:validators).each do |validator| validator.validate(self) end end base.send(:private, :run_validations) end
def validate *args
(**options)
-
:unless
(Symbol, String, Proc
) -- Specifies a method or -
:if
(Symbol, String, Proc
) -- Specifies a method or proc -
:on
(Symbol
) -- When this validation is run.
Parameters:
-
options
(Hash
) -- -
method_names
(Array
) -- A list of methods to call
Overloads:
-
validate(*method_names, options = {})
def validate *args validators << MethodValidator.new(self, *args) end
def validates_acceptance_of *args
(**options)
-
:unless
(Symbol, String, Proc
) -- Specifies a method or -
:if
(Symbol, String, Proc
) -- Specifies a method or proc -
:on
(Symbol
) -- When this validation is run. -
:allow_blank
(Boolean
) -- Skip validation if the -
:allow_nil
(Boolean
) -- Skip validation if the -
:message
(String
) -- A custom error message. The default -
:accpet
(mixed
) -- Specify an additional accepted value.
Parameters:
-
options
(Hash
) -- -
attributes
() -- A list of attribute names to validate.
Overloads:
-
validates_acceptance_of(*attributes, options = {}, &block)
Other tags:
- Note: - This validator should not be used with multi-valued attributes
Note: - Most validators default :allow_nil to false, this one defaults to true
def validates_acceptance_of *args validators << AcceptanceValidator.new(self, *args) end
def validates_confirmation_of *args
(**options)
-
:unless
(Symbol, String, Proc
) -- Specifies a method or -
:if
(Symbol, String, Proc
) -- Specifies a method or proc -
:on
(Symbol
) -- When this validation is run. -
:message
(String
) -- A custom error message. The default
Parameters:
-
options
(Hash
) -- -
attributes
() -- A list of attribute names to validate.
Overloads:
-
validates_confirmation_of(*attributes, options = {}, &block)
Other tags:
- Note: - This validation method does not accept the `:allow_nil` or the
def validates_confirmation_of *args validators << ConfirmationValidator.new(self, *args) end
def validates_count_of *args
(**options)
-
:unless
(Symbol, String, Proc
) -- Specifies a method or -
:if
(Symbol, String, Proc
) -- Specifies a method or proc -
:on
(Symbol
) -- When this validation is run. -
:wrong_number
(String
) -- An error message -
:too_few
(String
) -- An error message added -
:too_many
(String
) -- An error message added -
:maximum
(Integer
) -- The maximum number of values -
:minimum
(Integer
) -- The minimum number of values -
:within
(Range
) -- An range of number of values to -
:exactly
(Integer
) -- The exact number of values the
Parameters:
-
options
(Hash
) -- -
attributes
() -- A list of attribute names to validate.
Overloads:
-
validates_count_of(*attributes, options = {}, &block)
def validates_count_of *args validators << CountValidator.new(self, *args) end
def validates_each *attributes, &block
(**options)
-
:unless
(Symbol, String, Proc
) -- Specifies a method or -
:if
(Symbol, String, Proc
) -- Specifies a method or proc -
:on
(Symbol
) -- When this validation is run. -
:allow_blank
(Boolean
) -- Skip validation if the -
:allow_nil
(Boolean
) -- Skip validation if the
Parameters:
-
options
(Hash
) -- -
attributes
() -- A list of attribute names to validate.
Overloads:
-
validates_each(*attributes, options = {}, &block)
def validates_each *attributes, &block unless block_given? raise ArgumentError, 'missing required block for validates_each' end validators << BlockValidator.new(self, *attributes, &block) end
def validates_exclusion_of *args
(**options)
-
:unless
(Symbol, String, Proc
) -- Specifies a method or -
:if
(Symbol, String, Proc
) -- Specifies a method or proc -
:on
(Symbol
) -- When this validation is run. -
:allow_blank
(Boolean
) -- Skip validation if the -
:allow_nil
(Boolean
) -- Skip validation if the -
:message
(String
) -- A custom error message. The default -
:in
(required, Enumerable
) -- An enumerable object to
Parameters:
-
options
(Hash
) -- -
attributes
() -- A list of attribute names to validate.
Overloads:
-
validates_exclusion_of(*attributes, options = {}, &block)
def validates_exclusion_of *args validators << ExclusionValidator.new(self, *args) end
def validates_format_of *args
(**options)
-
:unless
(Symbol, String, Proc
) -- Specifies a method or -
:if
(Symbol, String, Proc
) -- Specifies a method or proc -
:on
(Symbol
) -- When this validation is run. -
:allow_blank
(Boolean
) -- Skip validation if the -
:allow_nil
(Boolean
) -- Skip validation if the -
:message
(String
) -- A custom error message. The default -
:without
(Regexp
) -- If the value matches the given -
:with
(Regexp
) -- If the value matches the given
Parameters:
-
options
(Hash
) -- -
attributes
() -- A list of attribute names to validate.
Overloads:
-
validates_format_of(*attributes, options = {}, &block)
def validates_format_of *args validators << FormatValidator.new(self, *args) end
def validates_inclusion_of *attributes
(**options)
-
:unless
(Symbol, String, Proc
) -- Specifies a method or -
:if
(Symbol, String, Proc
) -- Specifies a method or proc -
:on
(Symbol
) -- When this validation is run. -
:allow_blank
(Boolean
) -- Skip validation if the -
:allow_nil
(Boolean
) -- Skip validation if the -
:message
(String
) -- A custom error message. The default -
:in
(required, Enumerable
) -- An enumerable object to
Parameters:
-
options
(Hash
) -- -
attributes
() -- A list of attribute names to validate.
Overloads:
-
validates_inclusion_of(*attributes, options = {}, &block)
def validates_inclusion_of *attributes validators << InclusionValidator.new(self, *attributes) end
def validates_length_of *args
(**options)
-
:unless
(Symbol, String, Proc
) -- Specifies a method or -
:if
(Symbol, String, Proc
) -- Specifies a method or proc -
:on
(Symbol
) -- When this validation is run. -
:allow_blank
(Boolean
) -- Skip validation if the -
:allow_nil
(Boolean
) -- Skip validation if the -
:wrong_length
(String
) -- An error message -
:too_short
(String
) -- An error message added -
:too_long
(String
) -- An error message added -
:maximum
(Integer
) -- The maximum length an attribute -
:minimum
(Integer
) -- The minimum length an attribute -
:within
(Range
) -- An enumerable object which must -
:exactly
(Integer
) -- The exact length a value must be. -
:within
(Enumerable
) -- An enumerable object to
Parameters:
-
options
(Hash
) -- -
attributes
() -- A list of attribute names to validate.
Overloads:
-
validates_length_of(*attributes, options = {}, &block)
def validates_length_of *args validators << LengthValidator.new(self, *args) end
def validates_numericality_of *args
(**options)
-
:unless
(Symbol, String, Proc
) -- Specifies a method or -
:if
(Symbol, String, Proc
) -- Specifies a method or proc -
:on
(Symbol
) -- When this validation is run. -
:allow_blank
(Boolean
) -- Skip validation if the -
:allow_nil
(Boolean
) -- Skip validation if the -
:message
(String
) -- A custom error message. The default -
:odd
(Numeric
) -- If true, the value may only be -
:even
(Numeric
) -- If true, the value may only be -
:less_than_or_equal_to
(Integer
) -- Ensures the value is -
:less_than
(Numeric
) -- Ensures the attribute is less -
:greater_than_or_equal_to
(Integer
) -- Ensures the -
:greater_than
(Numeric
) -- Ensures the attribute -
:equal_to
(Integer
) -- When set the value must equal -
:only_integer
(Boolean
) -- Adds an error
Parameters:
-
options
(Hash
) -- -
attributes
() -- A list of attribute names to validate.
Overloads:
-
validates_numericality_of(*attributes, options = {}, &block)
def validates_numericality_of *args validators << NumericalityValidator.new(self, *args) end
def validates_presence_of *args
(**options)
-
:unless
(Symbol, String, Proc
) -- Specifies a method or -
:if
(Symbol, String, Proc
) -- Specifies a method or proc -
:allow_blank
(Boolean
) -- Skip validation if the -
:allow_nil
(Boolean
) -- Skip validation if the -
:on
(Symbol
) -- When this validation is run. -
:message
(String
) -- A custom error message. The default
Parameters:
-
options
(Hash
) -- -
attributes
() -- A list of attribute names to validate.
Overloads:
-
validates_presence_of(*attributes, options = {}, &block)
def validates_presence_of *args validators << PresenceValidator.new(self, *args) end
def validators
def validators @validators ||= [] end