Class: Spree::TaxIdentifiers::Validator::Base
- Inherits:
-
Object
- Object
- Spree::TaxIdentifiers::Validator::Base
- Defined in:
- app/models/spree/tax_identifiers/validator/base.rb
Overview
Contract for checking a buyer's tax registration. Registered per kind in Spree.tax_identifier_validators, because whether a number is well-formed and whether it is really registered are questions for the jurisdiction that issued it — not for the market's tax engine.
Two halves, deliberately split by cost: the format check is synchronous, offline and cheap enough to run on every save; the registry check makes a network call and runs in a job.
Direct Known Subclasses
Class Method Summary collapse
-
.checks_registry? ⇒ Boolean
Whether this validator can ask a registry at all.
-
.valid_format?(_value) ⇒ Boolean
Whether the value looks like a number of this kind.
Instance Method Summary collapse
-
#call(tax_identifier:) ⇒ Spree::TaxIdentifiers::ValidationResult
Asks the registry whether the number is registered.
Class Method Details
.checks_registry? ⇒ Boolean
Whether this validator can ask a registry at all. False for a format-only validator such as EuVat, and what stops core enqueueing a check nobody is going to answer — an unasked question is not an unavailable registry, and recording it as one would fill the admin with failures that mean nothing.
32 33 34 |
# File 'app/models/spree/tax_identifiers/validator/base.rb', line 32 def self.checks_registry? true end |
.valid_format?(_value) ⇒ Boolean
Whether the value looks like a number of this kind. Called on save, so it must not touch the network.
Permissive by default: a validator that only knows how to talk to a registry accepts anything core allowed through.
21 22 23 |
# File 'app/models/spree/tax_identifiers/validator/base.rb', line 21 def self.valid_format?(_value) true end |
Instance Method Details
#call(tax_identifier:) ⇒ Spree::TaxIdentifiers::ValidationResult
Asks the registry whether the number is registered. Runs in Spree::TaxIdentifiers::ValidateJob.
A registry that cannot answer must return an unavailable result
rather than raise: the number stays usable and the platform records
that nobody could answer.
47 48 49 |
# File 'app/models/spree/tax_identifiers/validator/base.rb', line 47 def call(tax_identifier:) raise NotImplementedError, "Please implement 'call' in your tax ID validator: #{self.class.name}" end |