Sha256: caf139a159e05b9785a0da0297c0f7ef26d999fcf3fe548e7b0ec6528342be33

Contents?: true

Size: 1.06 KB

Versions: 5

Compression:

Stored size: 1.06 KB

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
  #     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
  #     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
    include DateValidations

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ohm-contrib-0.0.28 lib/ohm/contrib/extra_validations.rb
ohm-contrib-0.0.27 lib/ohm/contrib/extra_validations.rb
ohm-contrib-0.0.26 lib/ohm/contrib/extra_validations.rb
ohm-contrib-0.0.25 lib/ohm/contrib/extra_validations.rb
ohm-contrib-0.0.24 lib/ohm/contrib/extra_validations.rb