validate-url-1.0.2/0000755000175000017500000000000012736222302014230 5ustar abhijithabhijithvalidate-url-1.0.2/metadata.yml0000644000175000017500000000524712736222302016543 0ustar abhijithabhijith--- !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.rb0000644000175000017500000000002612736222302015516 0ustar abhijithabhijithrequire 'validate_url'validate-url-1.0.2/LICENSE.md0000644000175000017500000000212712736222302015636 0ustar abhijithabhijithThe 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/0000755000175000017500000000000012736222302014776 5ustar abhijithabhijithvalidate-url-1.0.2/lib/locale/0000755000175000017500000000000012736222302016235 5ustar abhijithabhijithvalidate-url-1.0.2/lib/locale/de.yml0000644000175000017500000000007612736222302017353 0ustar abhijithabhijithde: errors: messages: url: ist keine gültige URL validate-url-1.0.2/lib/locale/pt-BR.yml0000644000175000017500000000010212736222302017675 0ustar abhijithabhijithpt-BR: errors: messages: url: não é uma URL válida validate-url-1.0.2/lib/locale/it.yml0000644000175000017500000000007512736222302017376 0ustar abhijithabhijithit: errors: messages: url: non è un URL valido. validate-url-1.0.2/lib/locale/tr.yml0000644000175000017500000000007712736222302017411 0ustar abhijithabhijithtr: errors: messages: url: Geçerli bir URL değil validate-url-1.0.2/lib/locale/ja.yml0000644000175000017500000000010012736222302017341 0ustar abhijithabhijithja: errors: messages: url: は不正なURLです。 validate-url-1.0.2/lib/locale/en.yml0000644000175000017500000000007212736222302017361 0ustar abhijithabhijithen: errors: messages: url: is not a valid URL validate-url-1.0.2/lib/validate_url.rb0000644000175000017500000000403012736222302017773 0ustar abhijithabhijithrequire '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.rb0000644000175000017500000000010312736222302016215 0ustar abhijithabhijithputs IO.read(File.join(File.dirname(__FILE__), 'README.markdown')) validate-url-1.0.2/README.md0000644000175000017500000000274212736222302015514 0ustar abhijithabhijith# 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.