Class: Matchd::Server
- Inherits:
-
Async::DNS::Server
- Object
- Async::DNS::Server
- Matchd::Server
- Defined in:
- lib/matchd/server.rb
Overview
Specific implementation of the Async::DNS::Server using a list of rules to determine it’s response
Rules will get #call‘ed in order until the first one matches (returns truthy). If none matches, a default Rule::Passthrough will get executed forwarding the query to the resolver defined via the `:resolver` option.
Instance Attribute Summary collapse
-
#resolver ⇒ Object
readonly
Returns the value of attribute resolver.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
Instance Method Summary collapse
-
#initialize(rules, listen, options = {}) ⇒ Server
constructor
A new instance of Server.
- #passthrough!(name, resource_class, transaction) ⇒ Object
- #process(name, resource_class, transaction) ⇒ Object
Constructor Details
#initialize(rules, listen, options = {}) ⇒ Server
Returns a new instance of Server.
15 16 17 18 19 20 21 22 23 |
# File 'lib/matchd/server.rb', line 15 def initialize(rules, listen, = {}) @rules = rules @resolver = .delete(:resolver) @forced_passthtough = .delete(:forced_passthtough) { true } listen = Matchd::Glue::AsyncEndpoint.parse(listen) super(listen, *) end |
Instance Attribute Details
#resolver ⇒ Object (readonly)
Returns the value of attribute resolver.
25 26 27 |
# File 'lib/matchd/server.rb', line 25 def resolver @resolver end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
25 26 27 |
# File 'lib/matchd/server.rb', line 25 def rules @rules end |
Instance Method Details
#passthrough!(name, resource_class, transaction) ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/matchd/server.rb', line 35 def passthrough!(name, resource_class, transaction) Matchd::Rule::Passthrough.new( "passthrough" => resolver, "match" => name, "resource_class" => resource_class, "force" => @forced_passthtough ).visit!(self, name, resource_class, transaction) end |
#process(name, resource_class, transaction) ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/matchd/server.rb', line 27 def process(name, resource_class, transaction) found = rules.any? do |rule| rule.call(self, name, resource_class, transaction) end passthrough!(name, resource_class, transaction) unless found end |