Class Index [+]

Quicksearch

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
36:       def self.any?(&block)
37:         stack.any?(&block)
38:       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
26:       def self.current
27:         stack.last
28:       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
14:       def self.in_context(context)
15:         stack << context
16:         yield
17:       ensure
18:         stack.pop
19:       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
45:       def self.stack
46:         Thread.current[:dm_validations_context_stack] ||= []
47:       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 #

@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
58:       def default_validation_context
59:         model.validators.current_context || :default
60:       end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.