simplificator / arext

Some ActiveRecord Extensions

This URL has Read+Write access

pascalbetz (author)
Wed May 27 23:40:40 -0700 2009
commit  ae4f818ec85470c9c88e7d278119265529703f0e
tree    328847f85debbc2a754483b0c6ed244d666c7083
parent  5fa50af9143d00caf8338d4bdedc7764985dedac
arext / README.rdoc
100644 54 lines (39 sloc) 1.814 kb

Arext

Active Record Extensions.

Validations

validates_constraints

This uses the information one can extract from ActiveRecord::ConnectionAdapter::Column to add default validations. The text?, limit and type methods are used to guess what validations are to be added validates_constraints make some assumptions (see below) and none of its behaviour is configurable. (you can always use the standard validations in addition to make some adjustments)

 * Adds validates_presence_of for columns with not null constraints (unless type is :boolean)
   * options are added so that empty strings will pass, unlike if you add the validate_presence_of yourself.
     If you want to have different behaviour then just add a validation yourself
 * Adds validates_inclusion_of(:in => [true, false]) for columns with not null constraints and :boolean type
 * Adds validates_length_of for text columns with not null limit

validates_url

This validator adds the feature to validate urls with http and https protocols. It also include portnumbers and any subdomains. Instead of a domain name, you can use ip address too (version 4).

validates_host

This validator adds the feature to validate a hostname. Instead of a hostname, you can use ip address too (version 4).

validates_email

This validator adds the feature to validate a email address.

Example

=

validates_constraints

in your ActiveRecord class:

 validate_constraints(:attribute_name, :other_attribute_name)

or

 validates_constraints() for all attributes

validates_url

in your ActiveRecord class:

  validates_url(:attribute)

validates_host

in your ActiveRecord class:

  validates_host(:attribute)

validates_email

in your ActiveRecord class:

  validates_email(:attribute)

Copyright © 2008 - now [simplificator gmbh]