pax_global_header00006660000000000000000000000064133755156710014527gustar00rootroot0000000000000052 comment=95d204d0d1d0774834b0d243278a2c475b88ec21 ruby-validate-email-0.1.6+git/000077500000000000000000000000001337551567100161475ustar00rootroot00000000000000ruby-validate-email-0.1.6+git/.gitignore000066400000000000000000000000531337551567100201350ustar00rootroot00000000000000coverage pkg rdoc test/tmp tmp .idea .rvmrcruby-validate-email-0.1.6+git/.rspec000066400000000000000000000000371337551567100172640ustar00rootroot00000000000000--colour --format documentationruby-validate-email-0.1.6+git/MIT-LICENSE000066400000000000000000000020731337551567100176050ustar00rootroot00000000000000Copyright (c) 2010 PerfectLine LLC (www.perfectline.co.uk) 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. ruby-validate-email-0.1.6+git/README.markdown000066400000000000000000000032731337551567100206550ustar00rootroot00000000000000# ValidateEmail This gem adds the capability of validating email addresses to `ActiveModel`. The gem only supports Rails 3 (has dependencies in ActiveModel and ActiveSupport 3.0) ### Installation # add this to your Gemfile gem "validate_email" # and then run rake gems:install # or just run sudo gem install validate_email ### Usage #### With ActiveRecord class Pony < ActiveRecord::Base # standard validation validates :email_address, :email => true # with allow_nil validates :email_address, :email => {:allow_nil => true} # with allow_blank validates :email_address, :email => {:allow_blank => true} end #### With ActiveModel class Unicorn include ActiveModel::Validations attr_accessor :email_address # with legacy syntax (the syntax above works also) validates_email :email_address, :allow_blank => true end #### I18n The error message will be looked up according to the standard ActiveModel::Errors scheme. For the above Unicorn class this would be: * activemodel.errors.models.unicorn.attributes.email_address.email * activemodel.errors.models.unicorn.email * activemodel.errors.messages.email * errors.attributes.email_address.email * errors.messages.email A default errors.messages.email of `is not a valid email address` is provided. You can also pass the `:message => "my custom error"` option to your validation to define your own custom message. ## Authors **Tanel Suurhans** () **Tarmo Lehtpuu** () ## License Copyright 2010 by PerfectLine LLC () and is released under the MIT license. ruby-validate-email-0.1.6+git/Rakefile000066400000000000000000000025701337551567100176200ustar00rootroot00000000000000require 'rake' require 'rake/clean' require 'rdoc/task' require 'rspec/core/rake_task' require 'jeweler' desc 'Default: run specs.' task :default => :spec Jeweler::Tasks.new do |jewel| jewel.name = 'validate_email' jewel.summary = 'Library for validating email addresses in Rails 3 models.' jewel.email = ['tanel.suurhans@perfectline.ee', 'tarmo.lehtpuu@perfectline.ee'] jewel.homepage = 'http://github.com/perfectline/validates_email/tree/master' jewel.description = 'Library for validating email addresses in Rails 3 models.' jewel.authors = ["Tanel Suurhans", "Tarmo Lehtpuu"] jewel.files = FileList["lib/**/*.rb", "lib/locale/*.yml", "*.rb", "MIT-LICENCE", "README.markdown"] jewel.add_development_dependency 'rspec' jewel.add_development_dependency 'diff-lcs', '>= 1.1.2' jewel.add_development_dependency 'active_record', '>= 3.0.0' jewel.add_development_dependency 'sqlite3-ruby' jewel.add_dependency 'mail', '>= 2.2.5' jewel.add_dependency 'activemodel', '>= 3.0' end desc 'Generate documentation plugin.' Rake::RDocTask.new(:rdoc) do |rdoc| rdoc.rdoc_dir = 'rdoc' rdoc.title = 'ValidatesEmail' rdoc.options << '--line-numbers' << '--inline-source' rdoc.rdoc_files.include('README.markdown') rdoc.rdoc_files.include('lib/**/*.rb') end desc 'Run all rspec tests' RSpec::Core::RakeTask.new ruby-validate-email-0.1.6+git/VERSION.yml000066400000000000000000000000531337551567100200150ustar00rootroot00000000000000--- :major: 0 :minor: 1 :patch: 6 :build: ruby-validate-email-0.1.6+git/init.rb000066400000000000000000000000311337551567100174310ustar00rootroot00000000000000require 'validate_email' ruby-validate-email-0.1.6+git/install.rb000066400000000000000000000001031337551567100201340ustar00rootroot00000000000000puts IO.read(File.join(File.dirname(__FILE__), 'README.markdown')) ruby-validate-email-0.1.6+git/lib/000077500000000000000000000000001337551567100167155ustar00rootroot00000000000000ruby-validate-email-0.1.6+git/lib/locale/000077500000000000000000000000001337551567100201545ustar00rootroot00000000000000ruby-validate-email-0.1.6+git/lib/locale/en.yml000066400000000000000000000001061337551567100212760ustar00rootroot00000000000000en: errors: messages: email: is not a valid email address ruby-validate-email-0.1.6+git/lib/validate_email.rb000066400000000000000000000015441337551567100222060ustar00rootroot00000000000000require 'active_support/i18n' I18n.load_path << File.dirname(__FILE__) + '/locale/en.yml' require 'active_model' require 'mail' module ActiveModel module Validations class EmailValidator < ActiveModel::EachValidator def initialize(options) options.reverse_merge!(:message => :email) super(options) end def validate_each(record, attribute, value) begin mail = Mail::Address.new(value) unless mail.address == value && mail.domain.split(".").length > 1 record.errors.add(attribute, options[:message]) end rescue record.errors.add(attribute, options[:message]) end end end module ClassMethods def validates_email(*attr_names) validates_with EmailValidator, _merge_attributes(attr_names) end end end end ruby-validate-email-0.1.6+git/spec/000077500000000000000000000000001337551567100171015ustar00rootroot00000000000000ruby-validate-email-0.1.6+git/spec/resources/000077500000000000000000000000001337551567100211135ustar00rootroot00000000000000ruby-validate-email-0.1.6+git/spec/resources/user.rb000066400000000000000000000001751337551567100224210ustar00rootroot00000000000000class User include ActiveModel::Validations attr_accessor :email_address validates :email_address, :email => true endruby-validate-email-0.1.6+git/spec/resources/user_with_ar.rb000066400000000000000000000002131337551567100241270ustar00rootroot00000000000000class UserWithAr < ActiveRecord::Base self.table_name = "users" validates :email_address, :email => { :message => "is not right" } endruby-validate-email-0.1.6+git/spec/resources/user_with_ar_legacy.rb000066400000000000000000000001551337551567100254600ustar00rootroot00000000000000class UserWithArLegacy < ActiveRecord::Base self.table_name = "users" validates_email :email_address endruby-validate-email-0.1.6+git/spec/resources/user_with_blank.rb000066400000000000000000000002301337551567100246130ustar00rootroot00000000000000class UserWithBlank include ActiveModel::Validations attr_accessor :email_address validates :email_address, :email => {:allow_blank => true} endruby-validate-email-0.1.6+git/spec/resources/user_with_legacy.rb000066400000000000000000000002611337551567100247740ustar00rootroot00000000000000class UserWithLegacy include ActiveModel::Validations attr_accessor :email_address validates_email :email_address, :allow_blank => true, :message => "is just wrong!" endruby-validate-email-0.1.6+git/spec/resources/user_with_nil.rb000066400000000000000000000002241337551567100243110ustar00rootroot00000000000000class UserWithNil include ActiveModel::Validations attr_accessor :email_address validates :email_address, :email => {:allow_nil => true} endruby-validate-email-0.1.6+git/spec/spec_helper.rb000066400000000000000000000014751337551567100217260ustar00rootroot00000000000000$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') $LOAD_PATH.unshift(File.dirname(__FILE__) + '/resources') $LOAD_PATH.unshift(File.dirname(__FILE__)) require 'validate_email' require 'rspec' require 'sqlite3' require 'active_record' require 'active_record/base' require 'active_record/migration' ActiveRecord::Migration.verbose = false ActiveRecord::Base.establish_connection( "adapter" => "sqlite3", "database" => ":memory:" ) require File.join(File.dirname(__FILE__), '..', 'init') autoload :User, 'resources/user' autoload :UserWithNil, 'resources/user_with_nil' autoload :UserWithBlank, 'resources/user_with_blank' autoload :UserWithLegacy, 'resources/user_with_legacy' autoload :UserWithAr, 'resources/user_with_ar' autoload :UserWithArLegacy, 'resources/user_with_ar_legacy'ruby-validate-email-0.1.6+git/spec/validate_email_spec.rb000066400000000000000000000103001337551567100233720ustar00rootroot00000000000000require 'spec_helper' describe "Email validation" do before(:all) do ActiveRecord::Schema.define(:version => 1) do create_table :users, :force => true do |t| t.column :email_address, :string end end end after(:all) do ActiveRecord::Base.connection.drop_table(:users) end context "with regular validator" do before do @user = User.new end it "should not allow nil as email" do @user.email_address = nil @user.should_not be_valid end it "should not allow blank as email" do @user.email_address = "" @user.should_not be_valid end it "should not allow an email without domain extension" do @user.email_address = "user@example" @user.should_not be_valid end it "should not allow an email without @" do @user.email_address = "user" @user.should_not be_valid end it "should not allow an email without prefix" do @user.email_address = "@example.com" @user.should_not be_valid end it "should not allow an email without domain" do @user.email_address = "user@.com" @user.should_not be_valid end it "should accept a valid email address" do @user.email_address = "user@example.com" @user.should be_valid end it "should return an error message" do @user.email_address = "bad" @user.valid? @user.errors[:email_address].should == ["is not a valid email address"] end end context "with allow nil" do before do @user = UserWithNil.new end it "should allow nil as email" do @user.email_address = nil @user.should be_valid end it "should not allow blank as email" do @user.email_address = "" @user.should_not be_valid end it "should allow a valid email address" do @user.email_address = "user@example.com" @user.should be_valid end it "should return an error message" do @user.email_address = "bad" @user.valid? @user.errors[:email_address].should == ["is not a valid email address"] end end context "with allow blank" do before do @user = UserWithBlank.new end it "should allow nil as email" do @user.email_address = nil @user.should be_valid end it "should allow blank as email" do @user.email_address = "" @user.should be_valid end it "should allow a valid email address" do @user.email_address = "user@example.com" @user.should be_valid end it "should return an error message" do @user.email_address = "bad" @user.valid? @user.errors[:email_address].should == ["is not a valid email address"] end end context "with legacy syntax" do before do @user = UserWithLegacy.new end it "should allow nil as email" do @user.email_address = nil @user.should be_valid end it "should allow blank as email" do @user.email_address = "" @user.should be_valid end it "should allow a valid email address" do @user.email_address = "user@example.com" @user.should be_valid end it "should not allow invalid email" do @user.email_address = "random" @user.should_not be_valid end it "should return an error message" do @user.email_address = "bad" @user.valid? @user.errors[:email_address].should == ["is just wrong!"] end end context "with ActiveRecord" do before do @user = UserWithAr.new end it "should not allow invalid email" do @user.email_address = "" @user.should_not be_valid end it "should return an error message" do @user.email_address = "bad" @user.valid? @user.errors[:email_address].should == ["is not right"] end end context "with ActiveRecord and legacy syntax" do before do @user = UserWithArLegacy.new end it "should not allow invalid email" do @user.email_address = "" @user.should_not be_valid end it "should return an error message" do @user.email_address = "bad" @user.valid? @user.errors[:email_address].should == ["is not a valid email address"] end end endruby-validate-email-0.1.6+git/validate_email.gemspec000066400000000000000000000040611337551567100224550ustar00rootroot00000000000000# Generated by jeweler # DO NOT EDIT THIS FILE DIRECTLY # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec' # -*- encoding: utf-8 -*- Gem::Specification.new do |s| s.name = "validate_email" s.version = "0.1.6" s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version= s.authors = ["Tanel Suurhans", "Tarmo Lehtpuu"] s.date = "2012-07-12" s.description = "Library for validating email addresses in Rails 3 models." s.email = ["tanel.suurhans@perfectline.ee", "tarmo.lehtpuu@perfectline.ee"] s.extra_rdoc_files = [ "README.markdown" ] s.files = [ "README.markdown", "init.rb", "install.rb", "lib/locale/en.yml", "lib/validate_email.rb" ] s.homepage = "http://github.com/perfectline/validates_email/tree/master" s.require_paths = ["lib"] s.rubygems_version = "1.8.24" s.summary = "Library for validating email addresses in Rails 3 models." if s.respond_to? :specification_version then s.specification_version = 3 if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then s.add_development_dependency(%q, [">= 0"]) s.add_development_dependency(%q, [">= 1.1.2"]) s.add_development_dependency(%q, [">= 3.0.0"]) s.add_development_dependency(%q, [">= 0"]) s.add_runtime_dependency(%q, [">= 2.2.5"]) s.add_runtime_dependency(%q, [">= 3.0"]) else s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 1.1.2"]) s.add_dependency(%q, [">= 3.0.0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 2.2.5"]) s.add_dependency(%q, [">= 3.0"]) end else s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 1.1.2"]) s.add_dependency(%q, [">= 3.0.0"]) s.add_dependency(%q, [">= 0"]) s.add_dependency(%q, [">= 2.2.5"]) s.add_dependency(%q, [">= 3.0"]) end end