Class: RubyDNS::RuleBasedServer::Rule
- Inherits:
-
Object
- Object
- RubyDNS::RuleBasedServer::Rule
- Defined in:
- lib/rubydns/server.rb
Overview
Represents a single rule in the server.
Instance Method Summary collapse
-
#call(server, name, resource_class, transaction) ⇒ Object
Invoke the rule, if it matches the incoming request, it is evaluated and returns
true
, otherwise returnsfalse
. -
#initialize(pattern, callback) ⇒ Rule
constructor
A new instance of Rule.
-
#match(name, resource_class) ⇒ Object
Returns true if the name and resource_class are sufficient:.
- #to_s ⇒ Object
Constructor Details
#initialize(pattern, callback) ⇒ Rule
Returns a new instance of Rule.
171 172 173 174 |
# File 'lib/rubydns/server.rb', line 171 def initialize(pattern, callback) @pattern = pattern @callback = callback end |
Instance Method Details
#call(server, name, resource_class, transaction) ⇒ Object
Invoke the rule, if it matches the incoming request, it is evaluated and returns true
, otherwise returns false
.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 |
# File 'lib/rubydns/server.rb', line 190 def call(server, name, resource_class, transaction) unless match(name, resource_class) server.logger.debug "<#{transaction.query.id}> Resource class #{resource_class} failed to match #{@pattern[1].inspect}!" return false end # Does this rule match against the supplied name? case @pattern[0] when Regexp match_data = @pattern[0].match(name) if match_data server.logger.debug "<#{transaction.query.id}> Regexp pattern matched with #{match_data.inspect}." @callback[transaction, match_data] return true end when String if @pattern[0] == name server.logger.debug "<#{transaction.query.id}> String pattern matched." @callback[transaction] return true end else if (@pattern[0].call(name, resource_class) rescue false) server.logger.debug "<#{transaction.query.id}> Callable pattern matched." @callback[transaction] return true end end server.logger.debug "<#{transaction.query.id}> No pattern matched." # We failed to match the pattern. return false end |
#match(name, resource_class) ⇒ Object
Returns true if the name and resource_class are sufficient:
177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/rubydns/server.rb', line 177 def match(name, resource_class) # If the pattern doesn't specify any resource classes, we implicitly pass this test: return true if @pattern.size < 2 # Otherwise, we try to match against some specific resource classes: if Class === @pattern[1] @pattern[1] == resource_class else @pattern[1].include?(resource_class) rescue false end end |
#to_s ⇒ Object
233 234 235 |
# File 'lib/rubydns/server.rb', line 233 def to_s @pattern.inspect end |