Module: DataMapper::Validations
- Extended by:
- Chainable
- Includes:
- Context
- Defined in:
- lib/dm-validations.rb,
lib/dm-validations/formats/url.rb,
lib/dm-validations/auto_validate.rb,
lib/dm-validations/formats/email.rb,
lib/dm-validations/support/context.rb,
lib/dm-validations/validation_errors.rb,
lib/dm-validations/contextual_validators.rb,
lib/dm-validations/validators/block_validator.rb,
lib/dm-validations/validators/format_validator.rb,
lib/dm-validations/validators/length_validator.rb,
lib/dm-validations/validators/method_validator.rb,
lib/dm-validations/validators/within_validator.rb,
lib/dm-validations/validators/generic_validator.rb,
lib/dm-validations/validators/numeric_validator.rb,
lib/dm-validations/validators/primitive_validator.rb,
lib/dm-validations/validators/acceptance_validator.rb,
lib/dm-validations/validators/uniqueness_validator.rb,
lib/dm-validations/validators/absent_field_validator.rb,
lib/dm-validations/validators/confirmation_validator.rb,
lib/dm-validations/validators/required_field_validator.rb
Defined Under Namespace
Modules: AutoValidations, ClassMethods, Context, Format, ValidatesAbsence, ValidatesAcceptance, ValidatesConfirmation, ValidatesFormat, ValidatesLength, ValidatesNumericality, ValidatesPresence, ValidatesPrimitiveType, ValidatesUniqueness, ValidatesWithBlock, ValidatesWithMethod, ValidatesWithin Classes: AbsenceValidator, AcceptanceValidator, ConfirmationValidator, ContextualValidators, FormatValidator, GenericValidator, LengthValidator, MethodValidator, NumericalityValidator, PresenceValidator, PrimitiveTypeValidator, UniquenessValidator, UnknownValidationFormat, ValidationErrors, WithinValidator
Class Method Summary collapse
Instance Method Summary collapse
-
#errors ⇒ Object
Return the ValidationErrors.
-
#valid?(context = :default) ⇒ Boolean
Check if a resource is valid in a given context.
-
#valid_for_default? ⇒ Boolean
Alias for valid?(:default).
-
#validatable? ⇒ Boolean
Mark this resource as validatable.
-
#validation_property(field_name) ⇒ Object
Get the corresponding Resource property, if it exists.
- #validation_property_value(name) ⇒ Object
Methods included from Context
Class Method Details
.included(model) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/dm-validations.rb', line 79 def self.included(model) model.class_eval <<-RUBY, __FILE__, __LINE__ + 1 def self.create(attributes = {}, *args) resource = new(attributes) resource.save(*args) resource end RUBY # models that are non DM resources must get .validators # and other methods, too model.extend ClassMethods end |
Instance Method Details
#errors ⇒ Object
Return the ValidationErrors
117 118 119 |
# File 'lib/dm-validations.rb', line 117 def errors @errors ||= ValidationErrors.new(self) end |
#valid?(context = :default) ⇒ Boolean
Check if a resource is valid in a given context
137 138 139 140 |
# File 'lib/dm-validations.rb', line 137 def valid?(context = :default) klass = respond_to?(:model) ? model : self.class klass.validators.execute(context, self) end |
#valid_for_default? ⇒ Boolean
Alias for valid?(:default)
131 132 133 |
# File 'lib/dm-validations.rb', line 131 def valid_for_default? valid?(:default) end |
#validatable? ⇒ Boolean
Mark this resource as validatable. When we validate associations of a resource we can check if they respond to validatable? before trying to recursivly validate them
125 126 127 |
# File 'lib/dm-validations.rb', line 125 def validatable? true end |
#validation_property(field_name) ⇒ Object
Get the corresponding Resource property, if it exists.
Note: DataMapper validations can be used on non-DataMapper resources. In such cases, the return value will be nil.
150 151 152 153 154 |
# File 'lib/dm-validations.rb', line 150 def validation_property(field_name) if respond_to?(:model) && (properties = model.properties(repository.name)) && properties.named?(field_name) properties[field_name] end end |
#validation_property_value(name) ⇒ Object
142 143 144 |
# File 'lib/dm-validations.rb', line 142 def validation_property_value(name) __send__(name) if respond_to?(name, true) end |