class Periphery::Runner

Attributes

binary_path[R]

Public Class Methods

new(binary_path) click to toggle source
# File lib/periphery/runner.rb, line 9
def initialize(binary_path)
  @binary_path = binary_path || "periphery"
end

Public Instance Methods

scan(options) click to toggle source
# 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) click to toggle source
# 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