class Guard::Julia::Runner

Runner that handles Julia calls and Guard notifications.

Attributes

options[RW]

Options for runner.

Public Class Methods

new(options = {}) click to toggle source

Initializes Runner.

@param options [Dict] Options for runner.

# File lib/guard/julia/runner.rb, line 11
def initialize(options = {})
  @options = {
    julia_file_path: 'julia',
    all_tests_file: 'test/runtests.jl',
    cli: ['--code-coverage'],
    env: {}
  }.merge(options)
end

Public Instance Methods

run_all() click to toggle source

Runs Julia on all tests file and notifies.

# File lib/guard/julia/runner.rb, line 21
def run_all
  paths = [@options[:all_tests_file]]
  ret_code = run_julia_command(paths)
  guard_notify(paths, ret_code)
end
run_on_modifications(paths) click to toggle source

Runs Julia on target paths (triggered by file modifications).

@param paths [Array<String>] Paths of files.

# File lib/guard/julia/runner.rb, line 30
def run_on_modifications(paths)
  return_code = run_julia_command(paths)
  guard_notify(paths, return_code)
end

Private Instance Methods

build_julia_command(paths) click to toggle source

Build Julia command from paths and options. Returns array of command parts.

# File lib/guard/julia/runner.rb, line 46
def build_julia_command(paths)
  cmd_parts = []
  cmd_parts << "#{@options[:julia_file_path]}"
  cmd_parts.push(*@options[:cli])
  cmd_parts.push(*paths)

  cmd_parts
end
guard_notify(paths, success) click to toggle source

Guard notification of Julia success/failure.

# File lib/guard/julia/runner.rb, line 56
def guard_notify(paths, success)
  # Build notification
  if success
    title = 'Success'
    message = paths.join('\n')
    image = :success
  else
    title = 'Failed'
    message = paths.join('\n')
    image = :failed
  end

  # Notify via Guard
  ::Guard::Notifier.notify(message, title: title, image: image)
end
run_julia_command(paths) click to toggle source

Runs Julia command from paths and options. Returns system return code.

# File lib/guard/julia/runner.rb, line 39
def run_julia_command(paths)
  cmd_parts = build_julia_command(paths)
  system(@options[:env], *cmd_parts)
end