Module: Ohm::ExtraValidations

Includes:
DateValidations, LengthValidations, NumberValidations, WebValidations
Defined in:
lib/ohm/contrib/extra_validations.rb

Overview

Includes Ohm::NumberValidations and Ohm::WebValidations.

Examples:


class Post < Ohm::Model
  include Ohm::ExtraValidations

  attribute :price
  attribute :state
  attribute :slug
  attribute :author_email
  attribute :url
  attribute :ipaddr
  attribute :birthday

  def validate
    super

    assert_decimal :price
    assert_member  :state, ['published', 'unpublished']
    assert_ipaddr  :ipaddr
    assert_url     :url
    assert_email   :author_email
    assert_date    :birthday
    assert_min_length :slug, 10
    assert_max_length :slug, 25
  end
end

post = Post.new
post.valid?
post.errors
# [[:price, :not_decimal], [:state, :not_member], [:ipaddr, :not_ipaddr],
#  [:url, :not_url], [:author_email, :not_email],[:slug, :too_short]]

Constant Summary

Constant Summary

Constants included from DateValidations

DateValidations::DATE_REGEX

Constants included from WebValidations

WebValidations::EMAIL_REGEX, WebValidations::IPV4_REGEX, WebValidations::SLUG_REGEX, WebValidations::URL_REGEX

Constants included from NumberValidations

NumberValidations::DECIMAL_REGEX

Method Summary

Methods included from LengthValidations

#assert_max_length, #assert_min_length

Methods included from DateValidations

#assert_date