Permalink
Browse files

Version 1.0

  • Loading branch information...
0 parents commit 91dd95884ddd6f79abaca768d909592bb7474b5e @RISCfuture committed Nov 1, 2010
Showing with 241 additions and 0 deletions.
  1. +5 −0 .document
  2. +25 −0 .gitignore
  3. +10 −0 Gemfile
  4. +41 −0 Gemfile.lock
  5. +20 −0 LICENSE
  6. +39 −0 README.textile
  7. +30 −0 Rakefile
  8. +1 −0 VERSION
  9. +50 −0 email_validation.gemspec
  10. +20 −0 lib/email_validation.rb
@@ -0,0 +1,5 @@
+README.rdoc
+lib/**/*.rb
+bin/*
+features/**/*.feature
+LICENSE
@@ -0,0 +1,25 @@
+## MAC OS
+.DS_Store
+
+## TEXTMATE
+*.tmproj
+tmtags
+
+## EMACS
+*~
+\#*
+.\#*
+
+## VIM
+*.swp
+
+## PROJECT::GENERAL
+coverage
+rdoc
+pkg
+.bundle
+.rvmrc
+
+## PROJECT::DOCUMENTATION
+.yardoc
+doc
10 Gemfile
@@ -0,0 +1,10 @@
+source :rubygems
+
+# DEPENDENCIES
+gem 'localized_each_validator', '>= 1.0.1'
+
+# DEVELOPMENT
+gem 'jeweler'
+gem 'yard'
+gem 'RedCloth', require: 'redcloth'
+
@@ -0,0 +1,41 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ RedCloth (4.2.3)
+ activemodel (3.0.1)
+ activesupport (= 3.0.1)
+ builder (~> 2.1.2)
+ i18n (~> 0.4.1)
+ activerecord (3.0.1)
+ activemodel (= 3.0.1)
+ activesupport (= 3.0.1)
+ arel (~> 1.0.0)
+ tzinfo (~> 0.3.23)
+ activesupport (3.0.1)
+ arel (1.0.1)
+ activesupport (~> 3.0.0)
+ builder (2.1.2)
+ gemcutter (0.6.1)
+ git (1.2.5)
+ i18n (0.4.2)
+ jeweler (1.4.0)
+ gemcutter (>= 0.1.0)
+ git (>= 1.2.5)
+ rubyforge (>= 2.0.0)
+ json_pure (1.4.6)
+ localized_each_validator (1.0.1)
+ activerecord (>= 3.0)
+ activesupport (>= 3.0)
+ rubyforge (2.0.4)
+ json_pure (>= 1.1.7)
+ tzinfo (0.3.23)
+ yard (0.6.1)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ RedCloth
+ jeweler
+ localized_each_validator (>= 1.0.1)
+ yard
20 LICENSE
@@ -0,0 +1,20 @@
+Copyright (c) 2010 Tim Morgan
+
+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.
@@ -0,0 +1,39 @@
+h1. email_validation -- Simple email validator for Rails 3
+
+| *Author* | Tim Morgan |
+| *Version* | 1.0 (Oct 30, 2010) |
+| *License* | Released under the MIT license. |
+
+h2. About
+
+This gem adds a very simple email address format validator to be used with ActiveRecord models in Rails 3.0. It supports localized error messages.
+
+h2. Installation
+
+Add the gem to your project's @Gemfile@:
+
+<pre><code>
+gem 'email_validation'
+</code></pre>
+
+h2. Usage
+
+This gem is an @EachValidator@, and thus is used with the @validates@ method:
+
+<pre><code>
+class User < ActiveRecord::Base
+ validates :email_address,
+ presence: true,
+ email: true
+end
+</code></pre>
+
+The localization key is @invalid_email@, and can be specified in the localized YAML file like so:
+
+<pre><code>
+en:
+ activerecord:
+ errors:
+ messages:
+ invalid_email: Email address is invalid.
+</code></pre>
@@ -0,0 +1,30 @@
+require 'rake'
+begin
+ require 'bundler'
+rescue LoadError
+ puts "Bundler is not installed; install with `gem install bundler`."
+ exit 1
+end
+
+Bundler.require :default
+
+Jeweler::Tasks.new do |gem|
+ gem.name = "email_validation"
+ gem.summary = %Q{Simple email validation in Rails 3}
+ gem.description = %Q{A simple, localizable EachValidator for email address fields in ActiveRecord 3.0.}
+ gem.email = "git@timothymorgan.info"
+ gem.homepage = "http://github.com/riscfuture/email_validation"
+ gem.authors = [ "Tim Morgan" ]
+ gem.add_dependency 'localized_each_validator', '>= 1.0.1'
+end
+Jeweler::GemcutterTasks.new
+
+YARD::Rake::YardocTask.new('doc') do |doc|
+ doc.options << "-m" << "textile"
+ doc.options << "--protected"
+ doc.options << "-r" << "README.textile"
+ doc.options << "-o" << "doc"
+ doc.options << "--title" << "email_validation Documentation".inspect
+
+ doc.files = [ 'lib/*_validator.rb', 'README.textile' ]
+end
@@ -0,0 +1 @@
+1.0.0
@@ -0,0 +1,50 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{email_validation}
+ s.version = "1.0.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Tim Morgan"]
+ s.date = %q{2010-10-31}
+ s.description = %q{A simple, localizable EachValidator for email address fields in ActiveRecord 3.0.}
+ s.email = %q{git@timothymorgan.info}
+ s.extra_rdoc_files = [
+ "LICENSE",
+ "README.textile"
+ ]
+ s.files = [
+ ".document",
+ ".gitignore",
+ "Gemfile",
+ "Gemfile.lock",
+ "LICENSE",
+ "README.textile",
+ "Rakefile",
+ "VERSION",
+ "email_validation.gemspec",
+ "lib/email_validation.rb"
+ ]
+ s.homepage = %q{http://github.com/riscfuture/email_validation}
+ s.rdoc_options = ["--charset=UTF-8"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.3.7}
+ s.summary = %q{Simple email validation in Rails 3}
+
+ if s.respond_to? :specification_version then
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<localized_each_validator>, [">= 1.0.1"])
+ else
+ s.add_dependency(%q<localized_each_validator>, [">= 1.0.1"])
+ end
+ else
+ s.add_dependency(%q<localized_each_validator>, [">= 1.0.1"])
+ end
+end
+
@@ -0,0 +1,20 @@
+require 'localized_each_validator'
+
+# Validates email addresses. Uses the @invalid_email@ error message key.
+#
+# @example
+# validates :email_address, email: true
+#
+# h2. Options
+#
+# | @:message@ | A custom message to use if the email is invalid. |
+# | @:allow_nil@ | If true, @nil@ values are allowed. |
+
+class EmailValidator < LocalizedEachValidator
+ error_key :invalid_email
+
+ # @private
+ def valid?(_, _, value)
+ value =~ /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i
+ end
+end

0 comments on commit 91dd958

Please sign in to comment.