validate-url-1.0.2/ 0000755 0001750 0001750 00000000000 12736222302 014230 5 ustar abhijith abhijith validate-url-1.0.2/metadata.yml 0000644 0001750 0001750 00000005247 12736222302 016543 0 ustar abhijith abhijith --- !ruby/object:Gem::Specification
name: validate_url
version: !ruby/object:Gem::Version
version: 1.0.2
platform: ruby
authors:
- Tanel Suurhans
- Tarmo Lehtpuu
- Vladimir Krylov
autorequire:
bindir: bin
cert_chain: []
date: 2015-07-21 00:00:00.000000000 Z
dependencies:
- !ruby/object:Gem::Dependency
name: activemodel
requirement: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: 3.0.0
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: 3.0.0
- !ruby/object:Gem::Dependency
name: addressable
requirement: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: '0'
type: :runtime
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: rspec
requirement: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: '0'
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: '0'
- !ruby/object:Gem::Dependency
name: diff-lcs
requirement: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: 1.1.2
type: :development
prerelease: false
version_requirements: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: 1.1.2
description: Library for validating urls in Rails.
email:
- tanel.suurhans@perfectline.co
- tarmo.lehtpuu@perfectline.co
- vladimir.krylov@perfectline.co
executables: []
extensions: []
extra_rdoc_files:
- LICENSE.md
- README.md
files:
- LICENSE.md
- README.md
- init.rb
- install.rb
- lib/locale/de.yml
- lib/locale/en.yml
- lib/locale/it.yml
- lib/locale/ja.yml
- lib/locale/pt-BR.yml
- lib/locale/tr.yml
- lib/validate_url.rb
homepage: http://github.com/perfectline/validates_url/tree/master
licenses: []
metadata: {}
post_install_message:
rdoc_options: []
require_paths:
- lib
required_ruby_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: '0'
required_rubygems_version: !ruby/object:Gem::Requirement
requirements:
- - ">="
- !ruby/object:Gem::Version
version: '0'
requirements: []
rubyforge_project:
rubygems_version: 2.4.5
signing_key:
specification_version: 4
summary: Library for validating urls in Rails.
test_files: []
validate-url-1.0.2/init.rb 0000644 0001750 0001750 00000000026 12736222302 015516 0 ustar abhijith abhijith require 'validate_url' validate-url-1.0.2/LICENSE.md 0000644 0001750 0001750 00000002127 12736222302 015636 0 ustar abhijith abhijith The MIT License (MIT)
Copyright (c) 2010 [PerfectLine](http://www.perfectline.co), LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. validate-url-1.0.2/lib/ 0000755 0001750 0001750 00000000000 12736222302 014776 5 ustar abhijith abhijith validate-url-1.0.2/lib/locale/ 0000755 0001750 0001750 00000000000 12736222302 016235 5 ustar abhijith abhijith validate-url-1.0.2/lib/locale/de.yml 0000644 0001750 0001750 00000000076 12736222302 017353 0 ustar abhijith abhijith de:
errors:
messages:
url: ist keine gültige URL
validate-url-1.0.2/lib/locale/pt-BR.yml 0000644 0001750 0001750 00000000102 12736222302 017675 0 ustar abhijith abhijith pt-BR:
errors:
messages:
url: não é uma URL válida
validate-url-1.0.2/lib/locale/it.yml 0000644 0001750 0001750 00000000075 12736222302 017376 0 ustar abhijith abhijith it:
errors:
messages:
url: non è un URL valido.
validate-url-1.0.2/lib/locale/tr.yml 0000644 0001750 0001750 00000000077 12736222302 017411 0 ustar abhijith abhijith tr:
errors:
messages:
url: Geçerli bir URL değil
validate-url-1.0.2/lib/locale/ja.yml 0000644 0001750 0001750 00000000100 12736222302 017341 0 ustar abhijith abhijith ja:
errors:
messages:
url: は不正なURLです。
validate-url-1.0.2/lib/locale/en.yml 0000644 0001750 0001750 00000000072 12736222302 017361 0 ustar abhijith abhijith en:
errors:
messages:
url: is not a valid URL
validate-url-1.0.2/lib/validate_url.rb 0000644 0001750 0001750 00000004030 12736222302 017773 0 ustar abhijith abhijith require 'addressable/uri'
require 'active_model'
require 'active_support/i18n'
I18n.load_path << File.dirname(__FILE__) + '/locale/en.yml'
I18n.load_path << File.dirname(__FILE__) + '/locale/tr.yml'
I18n.load_path << File.dirname(__FILE__) + '/locale/ja.yml'
module ActiveModel
module Validations
class UrlValidator < ActiveModel::EachValidator
def initialize(options)
options.reverse_merge!(:schemes => %w(http https))
options.reverse_merge!(:message => :url)
options.reverse_merge!(:no_local => false)
super(options)
end
def validate_each(record, attribute, value)
schemes = [*options.fetch(:schemes)].map(&:to_s)
begin
uri = Addressable::URI.parse(value)
unless uri && uri.host && schemes.include?(uri.scheme) && (!options.fetch(:no_local) || uri.host.include?('.'))
record.errors.add(attribute, options.fetch(:message), :value => value)
end
rescue Addressable::URI::InvalidURIError
record.errors.add(attribute, options.fetch(:message), :value => value)
end
end
end
module ClassMethods
# Validates whether the value of the specified attribute is valid url.
#
# class Unicorn
# include ActiveModel::Validations
# attr_accessor :homepage, :ftpsite
# validates_url :homepage, :allow_blank => true
# validates_url :ftpsite, :schemes => ['ftp']
# end
# Configuration options:
# * :message - A custom error message (default is: "is not a valid URL").
# * :allow_nil - If set to true, skips this validation if the attribute is +nil+ (default is +false+).
# * :allow_blank - If set to true, skips this validation if the attribute is blank (default is +false+).
# * :schemes - Array of URI schemes to validate against. (default is +['http', 'https']+)
def validates_url(*attr_names)
validates_with UrlValidator, _merge_attributes(attr_names)
end
end
end
end
validate-url-1.0.2/install.rb 0000644 0001750 0001750 00000000103 12736222302 016215 0 ustar abhijith abhijith puts IO.read(File.join(File.dirname(__FILE__), 'README.markdown'))
validate-url-1.0.2/README.md 0000644 0001750 0001750 00000002742 12736222302 015514 0 ustar abhijith abhijith # Validates URL
This gem adds the capability of validating URLs to ActiveRecord and ActiveModel (Rails 3).
## Installation
```
# add this to your Gemfile
gem "validate_url"
# and run
sudo gem install validate_url
```
## Usage
### With ActiveRecord
```ruby
class Pony < ActiveRecord::Base
# standard validation
validates :homepage, :url => true
# with allow_nil
validates :homepage, :url => {:allow_nil => true}
# with allow_blank
validates :homepage, :url => {:allow_blank => true}
# without local hostnames
validates :homepage, :url => {:no_local => true}
end
```
### With ActiveModel
```ruby
class Unicorn
include ActiveModel::Validations
attr_accessor :homepage
# with legacy syntax (the syntax above works also)
validates_url :homepage, :allow_blank => true
end
```
### I18n
The default error message `is not valid url`.
You can pass the `:message => "my custom error"` option to your validation to define your own, custom message.
## Contributing
Big thanks to Tanel Suurhans, Tarmo Lehtpuu, Steve Smith and all the [contributors](https://github.com/perfectline/validates_url/contributors)! We appreciate all your work on new features and bugfixes.
## Credits
Validates URL is created and maintained by [PerfectLine](http://www.perfectline.co), LLC.
## License
Validates URL is Copyright © 2010-2014 [PerfectLine](http://www.perfectline.co), LLC. It is free software, and may be
redistributed under the terms specified in the LICENSE file.