Class: Mixture::Validate::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/mixture/validate/base.rb

Overview

This class is abstract.

A base for validations. All validators should inherit this class.

Direct Known Subclasses

Exclusion, Inclusion, Length, Match, Presence

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

Initialize the validator.

Parameters:

  • options (Hash)

    The options for the validator.



23
24
25
# File 'lib/mixture/validate/base.rb', line 23

def initialize(options)
  @options = options
end

Class Method Details

.register_as(name) ⇒ void

This method returns an undefined value.

Registers this validator as the given name.

Parameters:

  • name (Symbol)

    The name of the validator.

See Also:



16
17
18
# File 'lib/mixture/validate/base.rb', line 16

def self.register_as(name)
  Validate.register(name, self)
end

Instance Method Details

#validate(record, attribute, value) ⇒ void

This method is abstract.

This method returns an undefined value.

Performs the validation.

Parameters:

  • record (Mixture::Model)

    The model that has the attribute. At least, it should respond to #errors.

  • attribute (Attribute)

    The attribute to validate.

  • value (Object)

    The value of the attribute.



35
36
37
38
39
# File 'lib/mixture/validate/base.rb', line 35

def validate(record, attribute, value)
  @record = record
  @attribute = attribute
  @value = value
end