Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jcf/validate_as_email
Validate email addresses with ActiveModel
https://github.com/jcf/validate_as_email
Last synced: 1 day ago
JSON representation
Validate email addresses with ActiveModel
- Host: GitHub
- URL: https://github.com/jcf/validate_as_email
- Owner: jcf
- License: mit
- Created: 2012-07-19T21:55:07.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2023-08-10T21:15:09.000Z (over 1 year ago)
- Last Synced: 2024-10-31T13:48:32.022Z (14 days ago)
- Language: Ruby
- Homepage:
- Size: 49.8 KB
- Stars: 11
- Watchers: 4
- Forks: 11
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Validate as Email [![Circle CI](https://circleci.com/gh/jcf/validate_as_email.svg?style=svg)](https://circleci.com/gh/jcf/validate_as_email)
Validation of email addresses via the excellent Mail gem that is
available in all Rails 3 and 4 applications.## Installation
Add this line to your application's Gemfile:
gem 'validate_as_email'
And then execute:
$ bundle
Or install it yourself as:
$ gem install validate_as_email
## Usage
This gem is tested against MRI, JRuby, and Rubinius using Travis CI.
You will need to be using Rails 3 or greater to make use of this
validator, as it is built on top of ActiveModel, which was introduced in
Rails 3.### Usage with ActiveModel
``` ruby
class Person
include ActiveModel::Validations
validates_as_email :email
attr_accessor :email
end# OR
class Person
include ActiveModel::Validations
validates :email, email: true
attr_accessor :email
end
```### Usage with ActiveRecord
``` ruby
class Person < ActiveRecord::Base
validates_as_email :email
attr_accessor :email
end# OR
class Person < ActiveRecord::Base
validates :email, email: true
attr_accessor :email
end
```### Built-in RSpec Matcher
The custom matcher will be loaded automatically if RSpec is loaded
first. Otherwise, you'll need to require the RSpec matcher manually
using `require 'validate_as_email/rspec'`.``` ruby
require 'validate_as_email/rspec'class Person < ActiveRecord::Base
validates_as_email :email
attr_accessor :email
enddescribe Person do
it { should have_a_valid_email_address_for(:email) }
it { should_not have_a_valid_email_address_for(:email) }
end
```## Contributing
1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create new Pull Request