Sha256: 8eeae3a5ec5556248e451011715c170d57785dd529d062dd5695ff592e542bc4

Contents?: true

Size: 1.74 KB

Versions: 6

Compression:

Stored size: 1.74 KB

Contents

= vidibus-validate_uri

This gem is part of the open source SOA framework Vidibus: http://www.vidibus.org

It provides validation of URIs (URLs) to ActiveModel records and ActionControllers in Rails 3.


== Installation

Add the dependency to the Gemfile of your application:

  gem "vidibus-validate_uri"

Then call bundle install on your console.


== Usage

To validate an URI in your ActiveModel record, simply add the uri validator to the field you want to validate as URI:

  class Model
    include Mongoid::Document
    field :some_uri
    validates :some_uri, :uri => true
  end
    
To validate an URI in any model, include ActiveModel::Validations:

  class Model
    include ActiveModel::Validations
    attr_accessor :uri
    validates :some_uri, :uri => true
  end
  
Just in case you'll need it, a method #valid_uri? is available to controllers that inherit from ActionController::Base. Use it like this:
  
  valid_uri?("something") # => false
  

=== Validation options

To restrict validation to a certain protocol, provide a :protocol option:

  validates :some_uri, :uri => { :protocol => :rtmp }
  validates :some_uri, :uri => { :protocol => [:rtsp, :rtmp] }
  
To check if the uri is accessible over the network, provide an :accessible option:

  validates :some_uri, :uri => { :accessible => true }

Just like for any other ActiveModel validation, you may allow blank values by providing an :allow_blank option:

  validates :some_uri, :uri => { :allow_blank => true }

You may provide those validation options to the #valid_uri? method as well:

  valid_uri?(your_uri, :accessible => true)
  valid_uri?(your_uri, :protocol => :rtmp)
  valid_uri?(your_uri, :protocol => [:rtsp, :rtmp])


== Copyright

Copyright (c) 2010 Andre Pankratz. See LICENSE for details.

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vidibus-validate_uri-0.1.5 README.rdoc
vidibus-validate_uri-0.1.4 README.rdoc
vidibus-validate_uri-0.1.3 README.rdoc
vidibus-validate_uri-0.1.2 README.rdoc
vidibus-validate_uri-0.1.1 README.rdoc
vidibus-validate_uri-0.1.0 README.rdoc