Class: MonoVM::Whois::Availability::Rule

Inherits:
Object
  • Object
show all
Defined in:
lib/monovm/whois/availability/rule.rb

Overview

One link in the detection chain.

A rule answers a single question about a response and either returns a Verdict — "I recognise this, here is the answer" — or nil, meaning "not mine, ask the next one". That is the whole contract, and it is what makes the chain extensible: a registry that invents new wording needs one more small object, not a change to Analyzer.

class MyRule < Availability::Rule
def call(context)
  return nil unless context.lower.include?("my special wording")

  registered(reason: "registry said so")
end
end

MonoVM::Whois.configure { |c| c.rules.prepend(MyRule.new) }

Instance Method Summary collapse

Instance Method Details

#call(context) ⇒ Verdict?

Parameters:

Returns:

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/monovm/whois/availability/rule.rb', line 43

def call(context)
  raise NotImplementedError, "#{self.class} must implement #call"
end

#nameObject

Identifier used in Verdict#rule and in the analyzer's trace. ServerRefusal becomes "server_refusal".

An anonymous class has no Module#name, so a rule defined inline — which is exactly how a host application tries one out — falls back to its inspect form rather than crashing.



33
34
35
36
37
38
39
# File 'lib/monovm/whois/availability/rule.rb', line 33

def name
  @name ||= begin
    base = self.class.name.to_s.split("::").last
    base = self.class.inspect if base.nil? || base.empty?
    base.gsub(/([a-z\d])([A-Z])/, '\1_\2').downcase
  end
end