Class: Mbeditor::AvailabilityProbe

Inherits:
Object
  • Object
show all
Defined in:
app/services/mbeditor/availability_probe.rb

Class Method Summary collapse

Class Method Details

.git(workspace_root) ⇒ Object



55
56
57
58
59
60
61
# File 'app/services/mbeditor/availability_probe.rb', line 55

def self.git(workspace_root)
  key = "git:#{workspace_root}"
  probe_cached(key) do
    _out, _err, status = Open3.capture3("git", "-C", workspace_root.to_s, "rev-parse", "--is-inside-work-tree")
    status.success?
  end
end

.haml_lint(workspace_root) ⇒ Object



46
47
48
49
50
51
52
53
# File 'app/services/mbeditor/availability_probe.rb', line 46

def self.haml_lint(workspace_root)
  cmd = haml_lint_command(workspace_root)
  key = "haml_lint:#{cmd.join(' ')}"
  probe_cached(key) do
    _out, _err, status = Open3.capture3(*cmd, "--version")
    status.success?
  end
end

.haml_lint_command(workspace_root) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
# File 'app/services/mbeditor/availability_probe.rb', line 25

def self.haml_lint_command(workspace_root)
  root = Pathname.new(workspace_root)
  workspace_bin = root.join("bin", "haml-lint")
  return [workspace_bin.to_s] if workspace_bin.exist?

  begin
    [Gem.bin_path("haml_lint", "haml-lint")]
  rescue Gem::Exception, Gem::GemNotFoundException
    ["haml-lint"]
  end
end

.reset!Object



63
64
65
66
# File 'app/services/mbeditor/availability_probe.rb', line 63

def self.reset!
  MUTEX.synchronize { @cache = {} }
  nil
end

.rubocop(workspace_root) ⇒ Object



37
38
39
40
41
42
43
44
# File 'app/services/mbeditor/availability_probe.rb', line 37

def self.rubocop(workspace_root)
  key = "rubocop:#{Mbeditor.configuration.rubocop_command}"
  probe_cached(key) do
    cmd = rubocop_command(workspace_root)
    _out, _err, status = Open3.capture3(*cmd, "--version")
    status.success?
  end
end

.rubocop_command(workspace_root) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/services/mbeditor/availability_probe.rb', line 11

def self.rubocop_command(workspace_root)
  root = Pathname.new(workspace_root)
  command = Mbeditor.configuration.rubocop_command.to_s.strip
  command = "rubocop" if command.empty?
  tokens = Shellwords.split(command)

  local_bin = root.join("bin", "rubocop")
  return [local_bin.to_s] if tokens == ["rubocop"] && local_bin.exist?

  tokens
rescue ArgumentError
  ["rubocop"]
end