Class: Coppertone::RecordFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/coppertone/record_finder.rb

Overview

A helper class for finding SPF records for a domain.

Instance Attribute Summary collapse

Instance Method Summary collapse

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_clientObject (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

#domainObject (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

#recordObject



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_recordsObject



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_recordsObject



32
33
34
# File 'lib/coppertone/record_finder.rb', line 32

def validate_txt_records
  raise AmbiguousSpfRecordError if txt_records.size > 1
end