Class: MonoVM::Whois::Availability::RuleSet
- Inherits:
-
Object
- Object
- MonoVM::Whois::Availability::RuleSet
- Includes:
- Enumerable
- Defined in:
- lib/monovm/whois/availability/rule_set.rb
Overview
The ordered chain of detection rules.
Order is the whole design. Two invariants hold it together:
- Rules that recognise a non-answer run first, so nothing that reaches the permissive rules could have been a refusal or a wrong-server reply.
- Every rule that concludes
:registeredruns before every rule that concludes:available, so when two signals conflict the safe one wins. Selling a registered domain is a far worse failure than telling a customer to check again.
The set is mutable so a host application can add a rule for a registry that invents new wording, without forking the gem or waiting for a release.
Class Method Summary collapse
-
.default ⇒ Object
The order shipped with the gem.
Instance Method Summary collapse
-
#append(rule) ⇒ Object
(also: #<<)
Add a rule at the very end, after the shipped fallbacks.
- #dup ⇒ Object
- #each ⇒ Object
- #include?(name) ⇒ Boolean
-
#initialize(rules = []) ⇒ RuleSet
constructor
A new instance of RuleSet.
- #insert_after(name, rule) ⇒ Object
-
#insert_before(name, rule) ⇒ Object
Insert
ruleimmediately before the named rule, which is usually what you want: a registry-specific check belongs next to the generic one it refines. - #inspect ⇒ Object
- #names ⇒ Object
-
#prepend(rule) ⇒ Object
Add a rule at the very front, ahead of even the refusal checks.
-
#remove(name) ⇒ Object
Drop a shipped rule, for a deployment that disagrees with one of them.
-
#replace(name, rule) ⇒ Object
Swap a rule's implementation, keeping its position.
- #size ⇒ Object
- #to_a ⇒ Object
Constructor Details
#initialize(rules = []) ⇒ RuleSet
Returns a new instance of RuleSet.
54 55 56 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 54 def initialize(rules = []) @rules = rules.dup end |
Class Method Details
.default ⇒ Object
The order shipped with the gem.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 37 def self.default new([ Rules::ServerRefusal.new, # non-answers first Rules::WrongRegistry.new, Rules::RdapObject.new, # structured, authoritative Rules::PremiumName.new, # premium is not available Rules::ExplicitUnavailability.new, # then everything meaning "registered" Rules::RegistrationFields.new, Rules::RegistryMarker.new, # then everything meaning "available" Rules::AvailabilityKeywords.new, Rules::NoMatch.new, Rules::TldSpecific.new, Rules::StatusField.new, Rules::Recordless.new # opt-in per TLD ]) end |
Instance Method Details
#append(rule) ⇒ Object Also known as: <<
Add a rule at the very end, after the shipped fallbacks.
81 82 83 84 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 81 def append(rule) @rules.push(rule) self end |
#dup ⇒ Object
118 119 120 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 118 def dup self.class.new(@rules) end |
#each ⇒ Object
58 59 60 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 58 def each(&) @rules.each(&) end |
#include?(name) ⇒ Boolean
114 115 116 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 114 def include?(name) @rules.any? { |rule| rule.name == name.to_s } end |
#insert_after(name, rule) ⇒ Object
97 98 99 100 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 97 def insert_after(name, rule) @rules.insert(index_of!(name) + 1, rule) self end |
#insert_before(name, rule) ⇒ Object
Insert rule immediately before the named rule, which is usually what you
want: a registry-specific check belongs next to the generic one it refines.
92 93 94 95 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 92 def insert_before(name, rule) @rules.insert(index_of!(name), rule) self end |
#inspect ⇒ Object
122 123 124 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 122 def inspect "#<#{self.class.name} #{names.join(" -> ")}>" end |
#names ⇒ Object
70 71 72 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 70 def names @rules.map(&:name) end |
#prepend(rule) ⇒ Object
Add a rule at the very front, ahead of even the refusal checks.
75 76 77 78 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 75 def prepend(rule) @rules.unshift(rule) self end |
#remove(name) ⇒ Object
Drop a shipped rule, for a deployment that disagrees with one of them.
103 104 105 106 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 103 def remove(name) @rules.delete_at(index_of!(name)) self end |
#replace(name, rule) ⇒ Object
Swap a rule's implementation, keeping its position.
109 110 111 112 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 109 def replace(name, rule) @rules[index_of!(name)] = rule self end |
#size ⇒ Object
66 67 68 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 66 def size @rules.size end |
#to_a ⇒ Object
62 63 64 |
# File 'lib/monovm/whois/availability/rule_set.rb', line 62 def to_a @rules.dup end |