Class: MonoVM::Whois::Availability::Rule
- Inherits:
-
Object
- Object
- MonoVM::Whois::Availability::Rule
- 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) }
Direct Known Subclasses
MonoVM::Whois::Availability::Rules::AvailabilityKeywords, MonoVM::Whois::Availability::Rules::ExplicitUnavailability, MonoVM::Whois::Availability::Rules::NoMatch, MonoVM::Whois::Availability::Rules::PremiumName, MonoVM::Whois::Availability::Rules::RdapObject, MonoVM::Whois::Availability::Rules::Recordless, MonoVM::Whois::Availability::Rules::RegistrationFields, MonoVM::Whois::Availability::Rules::RegistryMarker, MonoVM::Whois::Availability::Rules::ServerRefusal, MonoVM::Whois::Availability::Rules::StatusField, MonoVM::Whois::Availability::Rules::TldSpecific, MonoVM::Whois::Availability::Rules::WrongRegistry
Instance Method Summary collapse
- #call(context) ⇒ Verdict?
-
#name ⇒ Object
Identifier used in Verdict#rule and in the analyzer's trace.
Instance Method Details
#call(context) ⇒ Verdict?
43 44 45 |
# File 'lib/monovm/whois/availability/rule.rb', line 43 def call(context) raise NotImplementedError, "#{self.class} must implement #call" end |
#name ⇒ Object
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 |