Class: Periphery::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/periphery/runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(binary_path) ⇒ Runner

Returns a new instance of Runner.



9
10
11
# File 'lib/periphery/runner.rb', line 9

def initialize(binary_path)
  @binary_path = binary_path || "periphery"
end

Instance Attribute Details

#binary_pathObject (readonly)

Returns the value of attribute binary_path.



7
8
9
# File 'lib/periphery/runner.rb', line 7

def binary_path
  @binary_path
end

Instance Method Details

#scan(options) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/periphery/runner.rb', line 13

def scan(options)
  arguments = [binary_path, "scan"] + scan_arguments(options)
  stdout, stderr, status = Open3.capture3(*arguments)
  if status.success?
    stdout
  else
    raise "error: #{arguments} exited with status code #{status.exitstatus}. #{stderr}" unless status.success?
  end
end

#scan_arguments(options) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/periphery/runner.rb', line 23

def scan_arguments(options)
  options.
    lazy.
    select { |_key, value| value }.
    map { |key, value| value.kind_of?(TrueClass) ? [key, nil] : [key, value] }.
    map { |key, value| value.kind_of?(Array) ? [key, value.join(",")] : [key, value] }.
    map { |key, value| ["--#{key.to_s.tr('_', '-')}", value&.to_s] }.
    force.
    flatten.
    compact
end