Sha256: ad2378ac9e0278a4d7a85bb13524e2e1c27d8f45568e394336417bcfc413c65e

Contents?: true

Size: 1008 Bytes

Versions: 2

Compression:

Stored size: 1008 Bytes

Contents

module Ohm
  # Includes Ohm::NumberValidations and Ohm::WebValidations.
  #
  # @example
  #
  #   class Post < Ohm::Model
  #     include Ohm::ExtraValidations
  #     
  #     attribute :price
  #     attribute :state
  #     attribute :slug
  #     attribute :author_email
  #     attribute :url
  #     attribute :ipaddr
  #
  #     def validate
  #       super
  #
  #       assert_decimal :price
  #       assert_member  :state, ['published', 'unpublished']
  #       assert_ipaddr  :ipaddr
  #       assert_url     :url
  #       assert_email   :author_email
  #     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]]
  module ExtraValidations
    include NumberValidations
    include WebValidations

  protected
    def assert_member(att, set, error = [att, :not_member])
      assert set.include?(send(att)), error
    end    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ohm-contrib-0.0.16 lib/ohm/contrib/extra_validations.rb
ohm-contrib-0.0.15 lib/ohm/contrib/extra_validations.rb