class Mixture::Validate::Base
A base for validations. All validators should inherit this class.
@abstract
Public Class Methods
new(options)
click to toggle source
Initialize the validator.
@param options [Hash] The options for the validator.
# File lib/mixture/validate/base.rb, line 23 def initialize(options) @options = options end
register_as(name)
click to toggle source
Registers this validator as the given name.
@see Validate.register
@param name [Symbol] The name of the validator. @return [void]
# File lib/mixture/validate/base.rb, line 16 def self.register_as(name) Validate.register(name, self) end
Public Instance Methods
validate(record, attribute, value)
click to toggle source
Performs the validation.
@param record [Mixture::Model] The model that has the
attribute. At least, it should respond to `#errors`.
@param attribute [Attribute] The attribute to validate. @param value [Object] The value of the attribute. @return [void] @abstract
# File lib/mixture/validate/base.rb, line 35 def validate(record, attribute, value) @record = record @attribute = attribute @value = value end
Private Instance Methods
error(message)
click to toggle source
Raises an error with the given a message.
@param message [String] The message to raise. @raise [ValidationError]
# File lib/mixture/validate/base.rb, line 47 def error(message) fail ValidationError, message end