Class: Guard::Srb::Runner

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/guard/srb/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Runner

Returns a new instance of Runner.



14
15
16
17
# File 'lib/guard/srb/runner.rb', line 14

def initialize(options)
  @options = options
  @args_specified_by_user = T.let(nil, T.nilable(T::Array[String]))
end

Instance Method Details

#args_specified_by_userObject



50
51
52
53
54
55
56
57
58
59
60
# File 'lib/guard/srb/runner.rb', line 50

def args_specified_by_user
  @args_specified_by_user ||= begin
    args = @options[:cli]
    case args
    when Array    then args
    when String   then Shellwords.split(args)
    when NilClass then []
    else raise ArgumentError, ":cli option must be either an array or string"
    end
  end
end

#build_command(paths) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/guard/srb/runner.rb', line 37

def build_command(paths)
  command = [@options[:cmd] || "srb"]
  command.push("tc")

  command.push("--no-config") unless @options[:config]
  command.push("--color", @options[:colorize]) if @options[:colorize]
  command.push("--dir", ".")

  command.concat(args_specified_by_user)
  command.concat(paths)
end

#notify(result, success) ⇒ Object



63
64
65
66
67
# File 'lib/guard/srb/runner.rb', line 63

def notify(result, success)
  message = result.split("\n")[-1]
  image = success ? :success : :failed
  Notifier.notify(message, title: "Sorbet results", image: image)
end

#run(paths = []) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/guard/srb/runner.rb', line 20

def run(paths = [])
  command = build_command(paths)
  result, status = T.unsafe(Open3).capture2e(*command)

  case @options[:notification]
  when :failed
    notify(result, false) unless status.success?
  when true
    notify(result, status.success?)
  end

  warn(result) unless @options[:hide_stdout]

  status.success?
end