Module: Prremote::Mrbc

Defined in:
lib/prremote/mrbc.rb

Overview

mrbc lookup order:

1. MRBC env var if set (use this to point at a non-PATH binary)
2. PATH entries, excluding rbenv shims — shims delegate to the project's
   .ruby-version (typically CRuby) and do not work as a standalone mrbc
3. rbenv direct installs (~/.rbenv/versions/mruby-*/bin/mrbc)

The first candidate wins; version compatibility is checked in check_version!.

Constant Summary collapse

SHIMS_RE =
%r{\.rbenv/shims}
REQUIRED_MAJOR =
4

Class Method Summary collapse

Class Method Details

.binObject



14
15
16
17
18
19
# File 'lib/prremote/mrbc.rb', line 14

def self.bin
  return ENV['MRBC'] if ENV['MRBC'] && File.executable?(ENV['MRBC'])

  (path_candidates + rbenv_candidates).first ||
    raise('mrbc not found. Install mruby 4.x: brew install mruby')
end

.check_version!Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/prremote/mrbc.rb', line 32

def self.check_version!
  return if @version_ok

  major = major_version
  unless major && major >= REQUIRED_MAJOR
    raise "mrbc is mruby #{major || '?'}.x but mruby #{REQUIRED_MAJOR}.x or newer is required.\n" \
          "Installed: #{version}\n" \
          "Install mruby 4.x: brew install mruby\n" \
          "On Linux: build from source (https://github.com/mruby/mruby/releases)"
  end

  @version_ok = true
end

.major_versionObject



28
29
30
# File 'lib/prremote/mrbc.rb', line 28

def self.major_version
  version[/\bmruby (\d+)\./, 1]&.to_i
end

.versionObject



21
22
23
24
25
26
# File 'lib/prremote/mrbc.rb', line 21

def self.version
  out, = Open3.capture2e(bin, '--version')
  out.strip
rescue RuntimeError
  '(mrbc not found)'
end