Class: Coppertone::RecordFinder
- Inherits:
-
Object
- Object
- Coppertone::RecordFinder
- Defined in:
- lib/coppertone/record_finder.rb
Overview
A helper class for finding SPF records for a domain.
Instance Attribute Summary collapse
-
#dns_client ⇒ Object
readonly
Returns the value of attribute dns_client.
-
#domain ⇒ Object
readonly
Returns the value of attribute domain.
Instance Method Summary collapse
-
#initialize(dns_client, domain) ⇒ RecordFinder
constructor
A new instance of RecordFinder.
- #record ⇒ Object
- #txt_records ⇒ Object
- #validate_txt_records ⇒ Object
Constructor Details
#initialize(dns_client, domain) ⇒ RecordFinder
Returns a new instance of RecordFinder.
5 6 7 8 |
# File 'lib/coppertone/record_finder.rb', line 5 def initialize(dns_client, domain) @dns_client = dns_client @domain = domain end |
Instance Attribute Details
#dns_client ⇒ Object (readonly)
Returns the value of attribute dns_client.
4 5 6 |
# File 'lib/coppertone/record_finder.rb', line 4 def dns_client @dns_client end |
#domain ⇒ Object (readonly)
Returns the value of attribute domain.
4 5 6 |
# File 'lib/coppertone/record_finder.rb', line 4 def domain @domain end |
Instance Method Details
#record ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/coppertone/record_finder.rb', line 10 def record @record ||= begin validate_txt_records spf_dns_record = txt_records.first return nil unless spf_dns_record Record.new(spf_dns_record) end end |
#txt_records ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/coppertone/record_finder.rb', line 20 def txt_records @txt_records ||= begin if Coppertone::Utils::DomainUtils.valid?(domain) dns_client.fetch_txt_records(domain).map { |r| r[:text] } .select { |r| Record.record?(r) } else [] end end end |
#validate_txt_records ⇒ Object
32 33 34 |
# File 'lib/coppertone/record_finder.rb', line 32 def validate_txt_records raise AmbiguousSpfRecordError if txt_records.size > 1 end |