Class: DocktorRails::Platform
- Inherits:
-
Object
- Object
- DocktorRails::Platform
- Defined in:
- lib/docktor_rails/platform.rb
Instance Attribute Summary collapse
-
#arch ⇒ Object
readonly
Returns the value of attribute arch.
-
#os ⇒ Object
readonly
Returns the value of attribute os.
Class Method Summary collapse
Instance Method Summary collapse
- #amd64? ⇒ Boolean
- #arm64? ⇒ Boolean
-
#initialize(os:, arch:) ⇒ Platform
constructor
A new instance of Platform.
- #label ⇒ Object
- #linux? ⇒ Boolean
- #macos? ⇒ Boolean
- #to_h ⇒ Object
- #windows? ⇒ Boolean
Constructor Details
#initialize(os:, arch:) ⇒ Platform
Returns a new instance of Platform.
9 10 11 12 |
# File 'lib/docktor_rails/platform.rb', line 9 def initialize(os:, arch:) @os = os @arch = arch end |
Instance Attribute Details
#arch ⇒ Object (readonly)
Returns the value of attribute arch.
7 8 9 |
# File 'lib/docktor_rails/platform.rb', line 7 def arch @arch end |
#os ⇒ Object (readonly)
Returns the value of attribute os.
7 8 9 |
# File 'lib/docktor_rails/platform.rb', line 7 def os @os end |
Class Method Details
.detect ⇒ Object
14 15 16 |
# File 'lib/docktor_rails/platform.rb', line 14 def self.detect new(os: detect_os, arch: detect_arch) end |
.detect_arch ⇒ Object
55 56 57 58 59 60 61 |
# File 'lib/docktor_rails/platform.rb', line 55 def self.detect_arch cpu = RbConfig::CONFIG["host_cpu"].to_s.downcase return :arm64 if cpu.match?(/arm64|aarch64/) return :amd64 if cpu.match?(/x86_64|amd64/) :unknown end |
.detect_os ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/docktor_rails/platform.rb', line 46 def self.detect_os p = RUBY_PLATFORM return :windows if p.match?(/mswin|mingw|cygwin/i) return :macos if p.match?(/darwin/i) return :linux if p.match?(/linux/i) :unknown end |
Instance Method Details
#amd64? ⇒ Boolean
34 35 36 |
# File 'lib/docktor_rails/platform.rb', line 34 def amd64? arch == :amd64 end |
#arm64? ⇒ Boolean
30 31 32 |
# File 'lib/docktor_rails/platform.rb', line 30 def arm64? arch == :arm64 end |
#label ⇒ Object
42 43 44 |
# File 'lib/docktor_rails/platform.rb', line 42 def label "#{os} #{arch}" end |
#linux? ⇒ Boolean
26 27 28 |
# File 'lib/docktor_rails/platform.rb', line 26 def linux? os == :linux end |
#macos? ⇒ Boolean
22 23 24 |
# File 'lib/docktor_rails/platform.rb', line 22 def macos? os == :macos end |
#to_h ⇒ Object
38 39 40 |
# File 'lib/docktor_rails/platform.rb', line 38 def to_h { os: os.to_s, arch: arch.to_s } end |
#windows? ⇒ Boolean
18 19 20 |
# File 'lib/docktor_rails/platform.rb', line 18 def windows? os == :windows end |