Module: EmailAddress
- Defined in:
- lib/email_address.rb,
lib/email_address/host.rb,
lib/email_address/local.rb,
lib/email_address/config.rb,
lib/email_address/address.rb,
lib/email_address/version.rb,
lib/email_address/exchanger.rb,
lib/email_address/email_address_type.rb,
lib/email_address/active_record_validator.rb,
lib/email_address/canonical_email_address_type.rb
Overview
ActiveRecord v5.0 Custom Type
1) Register your types
# config/initializers/email_address.rb
ActiveRecord::Type.register(:email_address, EmailAddress::Address)
ActiveRecord::Type.register(:canonical_email_address,
EmailAddress::CanonicalEmailAddressType)
2) Define your email address columns in your model class
class User < ApplicationRecord
attribute :email, :email_address
attribute :canonical_email, :canonical_email_address
def email=(email_address)
self[:canonical_email] = email_address
self[:email] = email_address
end
end
3) Profit!
user = User.new(email:"[email protected]")
user.email #=> "[email protected]"
user.canonical_email #=> "[email protected]"
Defined Under Namespace
Modules: Rewriter Classes: ActiveRecordValidator, Address, CanonicalEmailAddressType, Config, EmailAddressType, Exchanger, Host, Local
Constant Summary collapse
- VERSION =
"0.2.5"
Class Method Summary collapse
-
.matches?(email_address, rules, config = {}, locale = "en") ⇒ Boolean
Does the email address match any of the given rules.
-
.new(email_address, config = {}, locale = "en") ⇒ Object
Creates an instance of this email address.
- .new_canonical(email_address, config = {}, locale = "en") ⇒ Object
- .new_redacted(email_address, config = {}, locale = "en") ⇒ Object
Class Method Details
.matches?(email_address, rules, config = {}, locale = "en") ⇒ Boolean
Does the email address match any of the given rules
64 65 66 |
# File 'lib/email_address.rb', line 64 def matches?(email_address, rules, config = {}, locale = "en") Address.new(email_address, config, locale).matches?(rules) end |
.new(email_address, config = {}, locale = "en") ⇒ Object
Creates an instance of this email address. This is a short-cut to EmailAddress::Address.new
51 52 53 |
# File 'lib/email_address.rb', line 51 def new(email_address, config = {}, locale = "en") Address.new(email_address, config, locale) end |