Class: Mihari::Enrichers::Base
- Defined in:
- lib/mihari/enrichers/base.rb
Overview
Base class for enrichers
Direct Known Subclasses
Constant Summary
Constants included from Concerns::Retriable
Concerns::Retriable::DEFAULT_CONDITION, Concerns::Retriable::RETRIABLE_ERRORS
Instance Attribute Summary
Attributes inherited from Actor
Class Method Summary collapse
Instance Method Summary collapse
-
#call(artifact) ⇒ Mihari::Models::Artifact
Enrich an artifact.
- #callable?(artifact) ⇒ Boolean
-
#initialize(options: nil) ⇒ Base
constructor
A new instance of Base.
- #result(artifact) ⇒ Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure
Methods inherited from Actor
configuration_keys, key, key_aliases, keys, #retry_exponential_backoff, #retry_interval, #retry_times, #timeout, type, #validate_configuration!
Methods included from Concerns::Retriable
Methods included from Concerns::Configurable
#configuration_keys?, #configured?
Constructor Details
#initialize(options: nil) ⇒ Base
Returns a new instance of Base.
12 13 14 |
# File 'lib/mihari/enrichers/base.rb', line 12 def initialize(options: nil) super end |
Class Method Details
.inherited(child) ⇒ Object
59 60 61 62 |
# File 'lib/mihari/enrichers/base.rb', line 59 def inherited(child) super Mihari.enrichers << child end |
Instance Method Details
#call(artifact) ⇒ Mihari::Models::Artifact
Enrich an artifact
23 24 25 |
# File 'lib/mihari/enrichers/base.rb', line 23 def call(artifact) raise NotImplementedError, "You must implement #{self.class}##{__method__}" end |
#callable?(artifact) ⇒ Boolean
54 55 56 |
# File 'lib/mihari/enrichers/base.rb', line 54 def callable?(artifact) callable_data_type?(artifact) && callable_relationships?(artifact) end |
#result(artifact) ⇒ Dry::Monads::Result::Success<Object>, Dry::Monads::Result::Failure
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/mihari/enrichers/base.rb', line 32 def result(artifact) return unless callable?(artifact) result = Try[StandardError] do retry_on_error(times: retry_times, interval: retry_interval, exponential_backoff: retry_exponential_backoff) do call artifact end end.to_result if result.failure? Mihari.logger.warn("Enricher:#{self.class.key} for #{artifact.data.truncate(32)} failed: #{result.failure}") end result end |