Sha256: e0b10fda9280755705ec80a638efb64ad517b5f26af4191b8061140bae50c86c

Contents?: true

Size: 1.28 KB

Versions: 13

Compression:

Stored size: 1.28 KB

Contents

# encoding: utf-8

module Mixture
  module Validate
    # A base for validations.  All validators should inherit this
    # class.
    #
    # @abstract
    class Base
      # Registers this validator as the given name.
      #
      # @see Validate.register
      # @param name [Symbol] The name of the validator.
      # @return [void]
      def self.register_as(name)
        Validate.register(name, self)
      end

      # Initialize the validator.
      #
      # @param options [Hash] The options for the validator.
      def initialize(options)
        @options = options
      end

      # 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
      def validate(record, attribute, value)
        @record = record
        @attribute = attribute
        @value = value
      end

      private

      # Raises an error with the given a message.
      #
      # @param message [String] The message to raise.
      # @raise [ValidationError]
      def error(message)
        fail ValidationError, message
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
mixture-0.6.2 lib/mixture/validate/base.rb
mixture-0.6.1 lib/mixture/validate/base.rb
mixture-0.6.0 lib/mixture/validate/base.rb
mixture-0.5.1 lib/mixture/validate/base.rb
mixture-0.5.0 lib/mixture/validate/base.rb
mixture-0.4.0 lib/mixture/validate/base.rb
mixture-0.3.6 lib/mixture/validate/base.rb
mixture-0.3.5 lib/mixture/validate/base.rb
mixture-0.3.4 lib/mixture/validate/base.rb
mixture-0.3.2 lib/mixture/validate/base.rb
mixture-0.3.1 lib/mixture/validate/base.rb
mixture-0.3.0 lib/mixture/validate/base.rb
mixture-0.2.0 lib/mixture/validate/base.rb