Class: TWPipeline::Stage

Inherits:
Object
  • Object
show all
Defined in:
lib/twpipeline/stage.rb,
sig/twpipeline.rbs

Constant Summary collapse

REGISTRY =

Returns:

  • (::Hash[::String, singleton(Stage)])
{}

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.

Parameters:

  • policy: (Object) (defaults to: TWFilter::Policy.corpus)
  • drop: (Boolean) (defaults to: false)
  • resources: (Resources) (defaults to: TWPipeline.resources)
  • options (Object)


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] (readonly)

Returns the value of attribute options.

Returns:

  • (::Hash[::Symbol, untyped])


34
35
36
# File 'lib/twpipeline/stage.rb', line 34

def options
  @options
end

#policyObject (readonly)

Returns the value of attribute policy.

Returns:

  • (Object)


34
35
36
# File 'lib/twpipeline/stage.rb', line 34

def policy
  @policy
end

#resourcesResources (readonly)

Returns the value of attribute resources.

Returns:



34
35
36
# File 'lib/twpipeline/stage.rb', line 34

def resources
  @resources
end

Class Method Details

.lookup(name) ⇒ singleton(Stage)

Parameters:

  • name (::String)

Returns:



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

Returns:

  • (::Integer)


16
# File 'lib/twpipeline/stage.rb', line 16

def order = @order

.ordered::Array[singleton(Stage)]

Returns:

  • (::Array[singleton(Stage)])


18
# File 'lib/twpipeline/stage.rb', line 18

def ordered = REGISTRY.values.sort_by(&:order)

.register(slug, order) ⇒ singleton(Stage)

Parameters:

  • slug (::String)
  • order (::Integer)

Returns:



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

Returns:

  • (::String)


14
# File 'lib/twpipeline/stage.rb', line 14

def slug = @slug

Instance Method Details

#call(input, output) ⇒ Object

Parameters:

  • input (Object)
  • output (Object)

Returns:

  • (Object)

Raises:

  • (NotImplementedError)


38
# File 'lib/twpipeline/stage.rb', line 38

def call(input, output) = raise NotImplementedError

#drop?Boolean

Returns:

  • (Boolean)


36
# File 'lib/twpipeline/stage.rb', line 36

def drop? = @drop

#flag(record, findings) ⇒ record

Parameters:

  • (record)
  • findings (::Array[untyped])

Returns:

  • (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

Parameters:

  • (record)
  • findings (::Array[untyped])

Returns:

  • (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