Module: Finesse::Platforms

Defined in:
lib/finesse/platforms.rb

Overview

Platform detection, binary resolution, and database.yml parsing.

Defined Under Namespace

Classes: UnsupportedPlatformError

Constant Summary collapse

SUPPORTED_PLATFORMS =
%w[
  arm64-darwin
  x86_64-darwin
  aarch64-linux
  x86_64-linux
].freeze
PLATFORM_MAP =
{
  %w[arm64 darwin] => 'arm64-darwin',
  %w[x86_64 darwin] => 'x86_64-darwin',
  %w[aarch64 linux] => 'aarch64-linux',
  %w[x86_64 linux] => 'x86_64-linux'
}.freeze

Class Method Summary collapse

Class Method Details

.cable_db_pathObject

Resolve the cable database path from config/database.yml. Returns nil if the file doesn't exist or no cable DB is configured.



53
54
55
56
57
58
59
# File 'lib/finesse/platforms.rb', line 53

def cable_db_path
  config = load_database_yml
  return nil unless config

  env_config = config.dig(ENV.fetch('RAILS_ENV', 'development'), 'cable')
  env_config['database'] if env_config.is_a?(Hash)
end

.executableObject



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/finesse/platforms.rb', line 39

def executable
  exe = File.join(root, 'exe', platform, 'finesse')

  unless File.exist?(exe)
    raise UnsupportedPlatformError,
          "Finesse binary not found at #{exe}. " \
          'Run `rake build:go` to compile from source.'
  end

  exe
end

.platformObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/finesse/platforms.rb', line 28

def platform
  cpu = Gem::Platform.local.cpu
  os = Gem::Platform.local.os

  PLATFORM_MAP.fetch([cpu, os]) do
    raise UnsupportedPlatformError,
          "Finesse does not support #{cpu}-#{os}. " \
          "Supported platforms: #{SUPPORTED_PLATFORMS.join(', ')}"
  end
end

.rootObject

Root directory of the gem (two levels up from lib/finesse/).



17
18
19
# File 'lib/finesse/platforms.rb', line 17

def root
  File.expand_path('../..', __dir__)
end