Sha256: 851f728f1698c82e743791e33d42c6b76791ce137e067ff07b8fd0aa7f4259b0

Contents?: true

Size: 1.13 KB

Versions: 13

Compression:

Stored size: 1.13 KB

Contents

module Ohm
  # All credit goes to gnrfan of github
  # Basically an extraction from http://github.com/gnrfan/ohm_extra_validations
  module WebValidations

  protected
    def assert_slug(att, error = [att, :not_slug])
      if assert_present(att, error) and assert_unique(att)
          assert_format(att, /^[-\w]+$/, error)
      end
    end

    def assert_email(att, error = [att, :not_email])
      if assert_present(att, error)
        assert_format(att, /^([^@\s*]+)@((?:[-a-z0-9]+\.)+[a-z]{2,6})$/i, error)
      end
    end

    def assert_url(att, error = [att, :not_url])
      if assert_present(att, error)
        assert_format(att, /^(http|https):\/\/([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}|(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}|localhost)(:[0-9]{1,5})?(\/.*)?$/ix, error)
      end
    end

    def assert_ipv4(att, error = [att, :not_ipv4])
      if assert_present(att, error)
        assert_format(att, /^(25[0-5]|2[0-4]\d|[0-1]?\d?\d)(\.(25[0-5]|2[0-4]\d|[0-1]?\d?\d)){3}$/, error)
      end
    end

    def assert_ipaddr(att, error = [att, :not_ipaddr])
        assert_ipv4(att, error)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
ohm-contrib-0.0.19 lib/ohm/contrib/web_validations.rb
ohm-contrib-0.0.18 lib/ohm/contrib/web_validations.rb
ohm-contrib-0.0.17 lib/ohm/contrib/web_validations.rb
ohm-contrib-0.0.14 lib/ohm/contrib/web_validations.rb
ohm-contrib-0.0.13 lib/ohm/contrib/web_validations.rb
ohm-contrib-0.0.12 lib/ohm/contrib/web_validations.rb
ohm-contrib-0.0.11 lib/ohm/contrib/web_validations.rb
ohm-contrib-0.0.10 lib/ohm/contrib/web_validations.rb
ohm-contrib-0.0.9 lib/ohm/contrib/web_validations.rb
ohm-contrib-0.0.8 lib/ohm/contrib/web_validations.rb
ohm-contrib-0.0.7 lib/ohm/contrib/web_validations.rb
ohm-contrib-0.0.6 lib/ohm/contrib/web_validations.rb
ohm-contrib-0.0.5 lib/ohm/contrib/web_validations.rb