Class: TWPipeline::Stage
- Inherits:
-
Object
show all
- Defined in:
- lib/twpipeline/stage.rb,
sig/twpipeline.rbs
Constant Summary
collapse
- REGISTRY =
{}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(policy: TWFilter::Policy.corpus, drop: false, resources: TWPipeline.resources, **options) ⇒ Stage
Returns a new instance of Stage.
27
28
29
30
31
32
|
# File 'lib/twpipeline/stage.rb', line 27
def initialize(policy: TWFilter::Policy.corpus, drop: false, resources: TWPipeline.resources, **options)
@policy = policy
@drop = drop
@resources = resources
@options = options
end
|
Instance Attribute Details
#options ⇒ ::Hash[::Symbol, untyped]
Returns the value of attribute options.
34
35
36
|
# File 'lib/twpipeline/stage.rb', line 34
def options
@options
end
|
#policy ⇒ Object
Returns the value of attribute policy.
34
35
36
|
# File 'lib/twpipeline/stage.rb', line 34
def policy
@policy
end
|
Returns the value of attribute resources.
34
35
36
|
# File 'lib/twpipeline/stage.rb', line 34
def resources
@resources
end
|
Class Method Details
.lookup(name) ⇒ singleton(Stage)
20
21
22
23
24
|
# File 'lib/twpipeline/stage.rb', line 20
def lookup(name)
REGISTRY[name] ||
REGISTRY.values.find { |stage| stage.slug.split("_", 2).last == name } ||
raise(Error, "unknown stage: #{name} (known: #{REGISTRY.keys.join(", ")})")
end
|
.order ⇒ ::Integer
16
|
# File 'lib/twpipeline/stage.rb', line 16
def order = @order
|
.ordered ⇒ ::Array[singleton(Stage)]
18
|
# File 'lib/twpipeline/stage.rb', line 18
def ordered = REGISTRY.values.sort_by(&:order)
|
.register(slug, order) ⇒ singleton(Stage)
8
9
10
11
12
|
# File 'lib/twpipeline/stage.rb', line 8
def register(slug, order)
@slug = slug
@order = order
REGISTRY[slug] = self
end
|
.slug ⇒ ::String
14
|
# File 'lib/twpipeline/stage.rb', line 14
def slug = @slug
|
Instance Method Details
#call(input, output) ⇒ Object
38
|
# File 'lib/twpipeline/stage.rb', line 38
def call(input, output) = raise NotImplementedError
|
#drop? ⇒ Boolean
36
|
# File 'lib/twpipeline/stage.rb', line 36
def drop? = @drop
|
#flag(record, findings) ⇒ record
46
47
48
49
50
51
|
# File 'lib/twpipeline/stage.rb', line 46
def flag(record, findings)
return record if findings.empty?
merged = record.fetch(:findings, []) + findings.map(&:to_h)
record.merge(ok: record.fetch(:ok, true) && findings.none?(&:reject?), findings: merged)
end
|
#reject(record, findings) ⇒ record
42
43
44
|
# File 'lib/twpipeline/stage.rb', line 42
def reject(record, findings)
record.merge(ok: false, findings: record.fetch(:findings, []) + findings.map(&:to_h))
end
|