Class: MailResolver::Testing::FakeResolver
- Inherits:
-
Object
- Object
- MailResolver::Testing::FakeResolver
- Defined in:
- lib/mailresolver/testing.rb
Overview
A zone in a hash. A name the zone doesn't mention raises NoSuchName, a name without records of the type asked for raises NotFound, and the sentinels :timeout, :servfail, and :nxdomain stand in for a resolver that misbehaves rather than one that answers nothing — a distinction SPF spends a lot of its rulebook on.
FakeResolver.new("example.com" => { txt: [ "v=spf1 -all" ], mx: :servfail })
PTR is keyed by the address the caller passes rather than by its reverse name: a zone written by hand reads better as "192.0.2.1".
Instance Attribute Summary collapse
-
#queries ⇒ Object
readonly
Returns the value of attribute queries.
Instance Method Summary collapse
- #a(name) ⇒ Object
- #aaaa(name) ⇒ Object
-
#addresses(name) ⇒ Object
A missing family contributes nothing; a name that doesn't exist at all, or a nameserver failure, still raises.
- #cname(name) ⇒ Object
-
#initialize(zone = {}) ⇒ FakeResolver
constructor
A new instance of FakeResolver.
- #mx(name) ⇒ Object
- #ptr(address) ⇒ Object
- #txt(name) ⇒ Object
Constructor Details
#initialize(zone = {}) ⇒ FakeResolver
Returns a new instance of FakeResolver.
23 24 25 26 |
# File 'lib/mailresolver/testing.rb', line 23 def initialize(zone = {}) @zone = zone.transform_keys { |name| normalized(name) } @queries = [] end |
Instance Attribute Details
#queries ⇒ Object (readonly)
Returns the value of attribute queries.
21 22 23 |
# File 'lib/mailresolver/testing.rb', line 21 def queries @queries end |
Instance Method Details
#a(name) ⇒ Object
32 33 34 |
# File 'lib/mailresolver/testing.rb', line 32 def a(name) lookup(name, :a) end |
#aaaa(name) ⇒ Object
36 37 38 |
# File 'lib/mailresolver/testing.rb', line 36 def aaaa(name) lookup(name, :aaaa) end |
#addresses(name) ⇒ Object
A missing family contributes nothing; a name that doesn't exist at all, or a nameserver failure, still raises. Resolver#addresses, exactly.
42 43 44 |
# File 'lib/mailresolver/testing.rb', line 42 def addresses(name) %i[ a aaaa ].flat_map { |type| family(type, name) } end |
#cname(name) ⇒ Object
54 55 56 |
# File 'lib/mailresolver/testing.rb', line 54 def cname(name) lookup(name, :cname) end |
#mx(name) ⇒ Object
46 47 48 |
# File 'lib/mailresolver/testing.rb', line 46 def mx(name) lookup(name, :mx) end |
#ptr(address) ⇒ Object
50 51 52 |
# File 'lib/mailresolver/testing.rb', line 50 def ptr(address) lookup(address, :ptr) end |
#txt(name) ⇒ Object
28 29 30 |
# File 'lib/mailresolver/testing.rb', line 28 def txt(name) lookup(name, :txt) end |