module AnyCableRailsGenerators::WithOSHelpers

Constants

CPU_NAMES
DEFAULT_BIN_PATH
OS_NAMES

Public Class Methods

included(base) click to toggle source
# File lib/generators/anycable/with_os_helpers.rb, line 9
def self.included(base)
  base.class_option :os,
    type: :string,
    desc: "Specify the OS for AnyCable-Go server binary (options: #{OS_NAMES.join(", ")})"
  base.class_option :cpu,
    type: :string,
    desc: "Specify the CPU architecturefor AnyCable-Go server binary (options: #{CPU_NAMES.join(", ")})"

  private :current_cpu, :supported_current_cpu, :supported_current_os
end

Public Instance Methods

cpu_name() click to toggle source
# File lib/generators/anycable/with_os_helpers.rb, line 41
def cpu_name
  options[:cpu] ||
    supported_current_cpu ||
    ask("What is your CPU architecture?", limited_to: CPU_NAMES)
end
current_cpu() click to toggle source
# File lib/generators/anycable/with_os_helpers.rb, line 20
def current_cpu
  case Gem::Platform.local.cpu
  when "x86_64", "x64"
    "amd64"
  when "x86_32", "x86", "i386", "i486", "i686"
    "i386"
  when "aarch64", "aarch64_be", /armv8/
    "arm64"
  when "arm", /armv7/, /armv6/
    "arm"
  else
    "unknown"
  end
end
os_name() click to toggle source
# File lib/generators/anycable/with_os_helpers.rb, line 35
def os_name
  options[:os] ||
    supported_current_os ||
    ask("What is your OS name?", limited_to: OS_NAMES)
end
supported_current_cpu() click to toggle source
# File lib/generators/anycable/with_os_helpers.rb, line 47
def supported_current_cpu
  CPU_NAMES.find(&current_cpu.method(:==))
end
supported_current_os() click to toggle source
# File lib/generators/anycable/with_os_helpers.rb, line 51
def supported_current_os
  OS_NAMES.find(&Gem::Platform.local.os.method(:==))
end