Module: DataMapper::Validations::AutoValidations

### Home Classes Methods

### In Files

- lib/dm-validations/auto_validate.rb

### Namespace

- MODULE DataMapper::Validations::AutoValidations::ModelExtension

### Methods

- ::generate_for_property
- #auto_validations_disabled?
- #disabled_auto_validations?
- #without_auto_validations

### Files

- LICENSE
- README.rdoc

### Class/Module Index

Quicksearch

- DataMapper
- DataMapper::InvalidContextError
- DataMapper::Validate
- DataMapper::ValidationError
- DataMapper::Validations
- DataMapper::Validations::AbsenceValidator
- DataMapper::Validations::AcceptanceValidator
- DataMapper::Validations::AutoValidations
- DataMapper::Validations::AutoValidations::ModelExtension
- DataMapper::Validations::ClassMethods
- DataMapper::Validations::ConfirmationValidator
- DataMapper::Validations::Context
- DataMapper::Validations::ContextualValidators
- DataMapper::Validations::Format
- DataMapper::Validations::Format::Email
- DataMapper::Validations::Format::Url
- DataMapper::Validations::FormatValidator
- DataMapper::Validations::GenericValidator
- DataMapper::Validations::LengthValidator
- DataMapper::Validations::MethodValidator
- DataMapper::Validations::NumericalityValidator
- DataMapper::Validations::OrderedHash
- DataMapper::Validations::PresenceValidator
- DataMapper::Validations::PrimitiveTypeValidator
- DataMapper::Validations::UniquenessValidator
- DataMapper::Validations::UnknownValidationFormat
- DataMapper::Validations::ValidatesAbsence
- DataMapper::Validations::ValidatesAcceptance
- DataMapper::Validations::ValidatesConfirmation
- DataMapper::Validations::ValidatesFormat
- DataMapper::Validations::ValidatesLength
- DataMapper::Validations::ValidatesNumericality
- DataMapper::Validations::ValidatesPresence
- DataMapper::Validations::ValidatesPrimitiveType
- DataMapper::Validations::ValidatesUniqueness
- DataMapper::Validations::ValidatesWithBlock
- DataMapper::Validations::ValidatesWithMethod
- DataMapper::Validations::ValidatesWithin
- DataMapper::Validations::ValidationErrors
- DataMapper::Validations::WithinValidator
- Object

No matching classes.

# DataMapper::Validations::AutoValidations

### Attributes

disable_auto_validations[R]

TODO: why are there 3 entry points to this ivar? disable_auto_validations, disabled_auto_validations?, auto_validations_disabled?

### Public Class Methods

generate_for_property(property) click to toggle source

Auto-generate validations for a given property. This will only occur if the option :auto_validation is either true or left undefined.

    Triggers that generate validator creation

    :required => true
        Setting the option :required to true causes a
        validates_presence_of validator to be automatically created on
        the property

    :length => 20
        Setting the option :length causes a validates_length_of
        validator to be automatically created on the property. If the
        value is a Integer the validation will set :maximum => value
        if the value is a Range the validation will set
        :within => value

    :format => :predefined / lambda / Proc
        Setting the :format option causes a validates_format_of
        validator to be automatically created on the property

    :set => ["foo", "bar", "baz"]
        Setting the :set option causes a validates_within
        validator to be automatically created on the property

    Integer type
        Using a Integer type causes a validates_numericality_of
        validator to be created for the property.  integer_only
        is set to true

    BigDecimal or Float type
        Using a Integer type causes a validates_numericality_of
        validator to be created for the property.  integer_only
        is set to false, and precision/scale match the property

    Messages

    :messages => {..}
        Setting :messages hash replaces standard error messages
        with custom ones. For instance:
        :messages => {:presence => "Field is required",
                      :format => "Field has invalid format"}
        Hash keys are: :presence, :format, :length, :is_unique,
                       :is_number, :is_primitive

    :message => "Some message"
        It is just shortcut if only one validation option is set

@api private

    # File lib/dm-validations/auto_validate.rb, line 101
    def self.generate_for_property(property)
      return if (property.model.disabled_auto_validations? ||
                 skip_auto_validation_for?(property))

      # all auto-validations (aside from presence) should skip
      # validation when the value is nil
      opts = { :allow_nil => true }

      if property.options.key?(:validates)
        opts[:context] = property.options[:validates]
      end

      infer_presence_validation_for(property, opts.dup)
      infer_length_validation_for(property, opts.dup)
      infer_format_validation_for(property, opts.dup)
      infer_uniqueness_validation_for(property, opts.dup)
      infer_within_validation_for(property, opts.dup)
      infer_type_validation_for(property, opts.dup)
    end

### Public Instance Methods

auto_validations_disabled?() click to toggle source

TODO: deprecate all but one of these 3 variants

Alias for: disabled_auto_validations?
disabled_auto_validations?() click to toggle source

Checks whether auto validations are currently disabled (see `disable_auto_validations` method that takes a block)

@return [TrueClass, FalseClass]

    true if auto validation is currently disabled

@api semipublic

    # File lib/dm-validations/auto_validate.rb, line 33
    def disabled_auto_validations?
      @disable_auto_validations || false
    end

Also aliased as: auto_validations_disabled?
without_auto_validations() click to toggle source

disables generation of validations for duration of given block

@api public

    # File lib/dm-validations/auto_validate.rb, line 44
    def without_auto_validations
      previous, @disable_auto_validations = @disable_auto_validations, true
      yield
    ensure
      @disable_auto_validations = previous
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.