Module: AnyCableRailsGenerators::WithOSHelpers

Included in:
DownloadGenerator
Defined in:
lib/generators/anycable/with_os_helpers.rb

Constant Summary collapse

OS_NAMES =
%w[linux darwin freebsd win].freeze
CPU_NAMES =
%w[amd64 arm64 386 arm].freeze
DEFAULT_BIN_PATH =
"/usr/local/bin"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
13
14
15
16
17
18
# 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

Instance Method Details

#cpu_nameObject



41
42
43
44
45
# 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_cpuObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
# 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", "arm64", /armv8/
    "arm64"
  when "arm", /armv7/, /armv6/
    "arm"
  else
    "unknown"
  end
end

#os_nameObject



35
36
37
38
39
# 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_cpuObject



47
48
49
# File 'lib/generators/anycable/with_os_helpers.rb', line 47

def supported_current_cpu
  CPU_NAMES.find(&current_cpu.method(:==))
end

#supported_current_osObject



51
52
53
# File 'lib/generators/anycable/with_os_helpers.rb', line 51

def supported_current_os
  OS_NAMES.find(&Gem::Platform.local.os.method(:==))
end