Class: Moderate::Filters::Base
- Inherits:
-
Object
- Object
- Moderate::Filters::Base
- Defined in:
- lib/moderate/filters/base.rb
Direct Known Subclasses
Class Method Summary collapse
-
.async? ⇒ Boolean
Is this adapter background-only? Default
false— the built-in deterministic adapters run inline. -
.classify(value) ⇒ Object
The class-level entry point the registry resolution path calls.
-
.synchronous? ⇒ Boolean
The predicate the spine's
Configuration#validate_block_mode_adapter!actually reads.
Instance Method Summary collapse
-
#classify(_value) ⇒ Object
Subclasses MUST implement
#classify(value) -> Moderate::Result.
Class Method Details
.async? ⇒ Boolean
Is this adapter background-only? Default false — the built-in
deterministic adapters run inline. Override with def self.async? = true
in an adapter whose classify does blocking I/O (a network moderation
API), so the gem routes it through Moderate::ClassifyJob in :flag mode
and forbids it in :block mode.
64 65 66 |
# File 'lib/moderate/filters/base.rb', line 64 def async? false end |
.classify(value) ⇒ Object
The class-level entry point the registry resolution path calls. Spins up a per-call instance so subclasses can keep per-classification state in instance vars without any thread-safety worry (a new instance per call).
55 56 57 |
# File 'lib/moderate/filters/base.rb', line 55 def classify(value) new.classify(value) end |
.synchronous? ⇒ Boolean
The predicate the spine's Configuration#validate_block_mode_adapter!
actually reads. Defined in terms of async? so there's a single source
of truth: an async adapter is, by definition, not synchronous.
71 72 73 |
# File 'lib/moderate/filters/base.rb', line 71 def synchronous? !async? end |
Instance Method Details
#classify(_value) ⇒ Object
Subclasses MUST implement #classify(value) -> Moderate::Result. We raise a
clear NotImplementedError rather than silently allowing nil, so a half-built
adapter fails loudly in development instead of mysteriously "allowing"
everything in production.
80 81 82 |
# File 'lib/moderate/filters/base.rb', line 80 def classify(_value) raise NotImplementedError, "#{self.class} must implement #classify(value) and return a Moderate::Result" end |