Class: Ronin::DB::EmailAddress
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Ronin::DB::EmailAddress
- Includes:
- Model, Model::Importable
- Defined in:
- lib/ronin/db/email_address.rb
Overview
Represents email addresses and their associated user names and host names.
Instance Attribute Summary collapse
-
#address ⇒ String
The raw string of the email address.
-
#created_at ⇒ Time
Tracks when the email address was created at.
-
#credentials ⇒ Array<Credential>
Any web credentials that are associated with the email address.
-
#host_name ⇒ HostName
The host-name component of the email address.
-
#id ⇒ Integer
The primary key of the email address.
-
#ip_addresses ⇒ Array<IPAddress>
Any IP addresses associated with the host name.
-
#user_name ⇒ UserName
The user-name component of the email address.
Class Method Summary collapse
-
.import(email) ⇒ EmailAddress
Imports an email address.
-
.lookup(email) ⇒ EmailAddress?
Looks up the email address.
-
.with_host_name(name) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given host name(s).
-
.with_ip_address(ip) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given IP address(es).
-
.with_user_name(name) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given user name(s).
Instance Method Summary collapse
-
#host ⇒ String
The host of the email address.
-
#to_s ⇒ String
Converts the email address into a String.
-
#user ⇒ String
The user of the email address.
Methods included from Model::Importable
Methods included from Model
Instance Attribute Details
#address ⇒ String
The raw string of the email address.
48 |
# File 'lib/ronin/db/email_address.rb', line 48 attribute :address, :string |
#created_at ⇒ Time
Tracks when the email address was created at.
87 |
# File 'lib/ronin/db/email_address.rb', line 87 attribute :created_at, :datetime |
#credentials ⇒ Array<Credential>
Any web credentials that are associated with the email address.
81 |
# File 'lib/ronin/db/email_address.rb', line 81 has_many :credentials, dependent: :destroy |
#host_name ⇒ HostName
The host-name component of the email address.
68 |
# File 'lib/ronin/db/email_address.rb', line 68 belongs_to :host_name, required: true |
#id ⇒ Integer
The primary key of the email address.
42 |
# File 'lib/ronin/db/email_address.rb', line 42 attribute :id, :integer |
#ip_addresses ⇒ Array<IPAddress>
Any IP addresses associated with the host name.
74 75 |
# File 'lib/ronin/db/email_address.rb', line 74 has_many :ip_addresses, through: :host_name, class_name: 'IPAddress' |
#user_name ⇒ UserName
The user-name component of the email address.
61 |
# File 'lib/ronin/db/email_address.rb', line 61 belongs_to :user_name, required: true |
Class Method Details
.import(email) ⇒ EmailAddress
Imports an email address.
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 |
# File 'lib/ronin/db/email_address.rb', line 161 def self.import(email) if email =~ /\s/ raise(ArgumentError,"email address #{email.inspect} must not contain spaces") end normalized_email = email.downcase user, host = normalized_email.split('@',2) if user.empty? raise(ArgumentError,"email address #{email.inspect} must have a user name") end if host.empty? raise(ArgumentError,"email address #{email.inspect} must have a host name") end return create( address: normalized_email, user_name: UserName.find_or_import(user), host_name: HostName.find_or_import(host) ) end |
.lookup(email) ⇒ EmailAddress?
Looks up the email address.
143 144 145 |
# File 'lib/ronin/db/email_address.rb', line 143 def self.lookup(email) find_by(address: email) end |
.with_host_name(name) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given host name(s).
100 101 102 |
# File 'lib/ronin/db/email_address.rb', line 100 def self.with_host_name(name) joins(:host_name).where(host_name: {name: name}) end |
.with_ip_address(ip) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given IP address(es).
115 116 117 |
# File 'lib/ronin/db/email_address.rb', line 115 def self.with_ip_address(ip) joins(:ip_addresses).where(ip_addresses: {address: ip}) end |
.with_user_name(name) ⇒ Array<EmailAddress>
Searches for email addresses associated with the given user name(s).
130 131 132 |
# File 'lib/ronin/db/email_address.rb', line 130 def self.with_user_name(name) joins(:user_name).where(user_name: {name: name}) end |
Instance Method Details
#host ⇒ String
The host of the email address.
204 205 206 |
# File 'lib/ronin/db/email_address.rb', line 204 def host self.host_name.name if self.host_name end |
#to_s ⇒ String
Converts the email address into a String.
216 217 218 |
# File 'lib/ronin/db/email_address.rb', line 216 def to_s "#{self.user_name}@#{self.host_name}" end |
#user ⇒ String
The user of the email address.
192 193 194 |
# File 'lib/ronin/db/email_address.rb', line 192 def user self.user_name.name if self.user_name end |