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.


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

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:


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

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.


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

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