Class | DataMapper::Validations::ContextualValidators |
In: |
lib/dm-validations/contextual_validators.rb
|
Parent: | Object |
@author Guy van den Berg @since 0.9
attributes | [R] | |
contexts | [R] |
Create a new validator of the given klazz and push it onto the requested context for each of the attributes in attributes
@param [DataMapper::Validations::GenericValidator] validator_class
Validator class, example: DataMapper::Validations::LengthValidator
@param [Array<Symbol>] attributes
Attribute names given to validation macro, example: [:first_name, :last_name] in validates_presence_of :first_name, :last_name
@param [Hash] options
Options supplied to validation macro, example: {:context=>:default, :maximum=>50, :allow_nil=>true, :message=>nil}
@option [Symbol] :context
the context in which the new validator should be run
@option [Boolean] :allow_nil
whether or not the new validator should allow nil values
@option [Boolean] :message
the error message the new validator will provide on validation failure
Assert that the given context is valid for this model
@param [Symbol] context
the context to test
@raise [InvalidContextError]
raised if the context is not valid for this model
@api private
TODO: is this method actually needed?
Return an array of validators for a named property
@param [Symbol]
Property name for which to return validators
@return [Array<DataMapper::Validations::GenericValidator>]
An array of validators bound to the given property
Return an array of validators for a named context
@param [String]
Context name for which to return validators
@return [Array<DataMapper::Validations::GenericValidator>]
An array of validators bound to the given context
Returns the current validation context on the stack if valid for this model, nil if no contexts are defined for the model (and no contexts are on the validation stack), or :default if the current context is invalid for this model or no contexts have been defined for this model and no context is on the stack.
@return [Symbol]
the current validation context from the stack (if valid for this model), nil if no context is on the stack and no contexts are defined for this model, or :default if the context on the stack is invalid for this model or no context is on the stack and this model has at least one validation context
@api private
TODO: simplify the semantics of current_context, valid?
Execute all validators in the named context against the target. Load together any properties that are designated lazy but are not yet loaded.
@param [Symbol] named_context
the context we are validating against
@param [Object] target
the resource that we are validating
@return [Boolean]
true if all are valid, otherwise false
Clean up the argument list and return a opts hash, including the merging of any default opts. Set the context to default if none is provided. Also allow :context to be aliased to :on, :when & :group
@param [Hash] options
the options to be normalized
@param [NilClass, Hash] defaults
default keys/values to set on normalized options
@return [Hash]
the normalized options
@api private