Module: DataMapper::Validations::Context

### Home Classes Methods

### In Files

- lib/dm-validations/context.rb

### Methods

- ::any?
- ::current
- ::in_context
- ::stack
- #default_validation_context

### 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::Context

Module with validation context functionality.

Contexts are implemented using a thread-local array-based stack.

### Public Class Methods

any?(&block) click to toggle source

Are there any contexts on the stack?

@return [Boolean]

    true/false whether there are any contexts on the context stack

@api semipublic

    # File lib/dm-validations/context.rb, line 36
    def self.any?(&block)
      stack.any?(&block)
    end

current() click to toggle source

Get the current validation context or nil (if no context is on the stack).

@return [Symbol, NilClass]

    The current validation context (for the current thread),
    or nil if no current context is on the stack

    # File lib/dm-validations/context.rb, line 26
    def self.current
      stack.last
    end

in_context(context) click to toggle source

Execute a block of code within a specific validation context

@param [Symbol] context

    the context to execute the block of code within

@api semipublic

    # File lib/dm-validations/context.rb, line 14
    def self.in_context(context)
      stack << context
      yield
    ensure
      stack.pop
    end

stack() click to toggle source

The (thread-local) validation context stack This allows object graphs to be saved within potentially nested contexts without having to pass the validation context throughout

@api private

    # File lib/dm-validations/context.rb, line 45
    def self.stack
      Thread.current[:dm_validations_context_stack] ||= []
    end

### Public Instance Methods

default_validation_context() click to toggle source

The default validation context for this Resource. This Resource's default context can be overridden by implementing default_validation_context

@return [Symbol]

    the current validation context from the context stack
    (if valid for this model), or :default

@api semipublic

    # File lib/dm-validations/context.rb, line 58
    def default_validation_context
      model.validators.current_context || :default
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.