Class: Threatinator::CLI::RunActionBuilder

Inherits:
ActionBuilder show all
Defined in:
lib/threatinator/cli/run_action_builder.rb

Instance Attribute Summary

Attributes inherited from ActionBuilder

#config_hash, #extra_args

Instance Method Summary collapse

Methods inherited from ActionBuilder

#feed_registry

Constructor Details

#initialize(opts, args, config_class) ⇒ RunActionBuilder

Returns a new instance of RunActionBuilder.



9
10
11
12
# File 'lib/threatinator/cli/run_action_builder.rb', line 9

def initialize(opts, args, config_class)
  super(opts, args)
  @config_class = config_class
end

Instance Method Details

#buildObject



14
15
16
# File 'lib/threatinator/cli/run_action_builder.rb', line 14

def build
  Threatinator::Actions::Run::Action.new(feed_registry, config)
end

#configObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/threatinator/cli/run_action_builder.rb', line 18

def config
  run_hash = config_hash["run"] || {}
  run_hash['observers'] ||= []

  if filename = run_hash['coverage_output']
    observer = Threatinator::Actions::Run::CoverageObserver.new(filename)
    run_hash['observers'] << observer
  end

  config = @config_class.new(run_hash)

  if config.feed_provider.nil? && provider = extra_args.shift
    config.feed_provider = provider
  end

  if config.feed_name.nil? && name = extra_args.shift
    config.feed_name = name
  end
  config
end