host-os 0.2.3 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e4d4c55e46c861d21e6c2870483c2fcdde4363dbd258dbcc8dd90151c695dfd3
4
- data.tar.gz: f22941bb284272fdc2e981853d993a68f855c9fa2e991b50e69d79ba9e193ae7
3
+ metadata.gz: 6911e87a33d86796f13712244715bd4674550d7aab285e0b74b46a60bdbc1fee
4
+ data.tar.gz: 1bea2940bb32647883bda9d6d31351acf00c446eaa1e9ab61830955aa23af252
5
5
  SHA512:
6
- metadata.gz: ce5dfb8a75cc6f71e1ff527ca00460616a0a8e7feb9578a07bb365a0e6d40969070b5af5a6b9f146570a9df85557e0e0ad1a3ea4e645a495d5ecb62a91679d13
7
- data.tar.gz: 8468203ff0fda61f4e2973c0ad6754aa226b6b3f754363ed7d27c86ca83d59333b0030504e9a5380dc4d8229267dd74e4ce2ff529b7336fa684f3d6db1666b12
6
+ metadata.gz: 494c3eb435deb200f27f605ce6f9a3ffb21c2b602b552fa5b4ac3b122298b53f12139775580adb1d079f1bd418a6fee5653ea3bc5e326594b1e222c917e945cc
7
+ data.tar.gz: ce7457278f78b6285044bb3a0a54dd341be3d862eb3b5c415879fb078e4114ac9edaa08f1cdfebf8c1bd249968b3ecfc6fc18e962756ebfaad415dcf53221211
data/README.md CHANGED
@@ -1,10 +1,10 @@
1
- # HostOS ![version](https://img.shields.io/gem/v/host-os?label=)
1
+ # HostOS v0.4.0
2
2
 
3
3
  HostOS is a module that offers details about the host operating system, the current Ruby interpreter, and the environment currently in use.
4
4
 
5
5
  - Gem: [rubygems.org](https://rubygems.org/gems/host-os)
6
6
  - Source: [codeberg.org](https://codeberg.org/mblumtritt/host-os)
7
- - Help: [rubydoc.info](https://rubydoc.info/gems/host-os/HostOS)
7
+ - Help: [rubydoc.info](https://rubydoc.info/gems/host-os/0.4.0/HostOS)
8
8
 
9
9
  ## Description
10
10
 
@@ -79,7 +79,7 @@ This gem is compatible with Ruby 2.3 and higher. You can install it in your syst
79
79
  gem install host-os
80
80
  ```
81
81
 
82
- or you can use [Bundler](http://gembundler.com/) to add HostOS just to your own project:
82
+ or you can use [Bundler](https://bundler.io) to add HostOS just to your own project:
83
83
 
84
84
  ```shell
85
85
  bundle add 'host-os'
data/examples/current.rb CHANGED
@@ -12,7 +12,7 @@
12
12
  # $ ENV=test ruby examples/current.rb
13
13
  #
14
14
 
15
- require 'host-os/support'
15
+ require_relative '../lib/host-os/support'
16
16
 
17
17
  puts <<~INFORMATION
18
18
  # OS Information
data/host-os.gemspec ADDED
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/host-os/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'host-os'
7
+ spec.version = HostOS::VERSION
8
+ spec.summary = <<~SUMMARY.tr("\n", ' ')
9
+ This module offers details on the host OS, the present Ruby interpreter
10
+ and environment.
11
+ SUMMARY
12
+ spec.description = <<~DESCRIPTION.tr("\n", ' ')
13
+ This gem helps you write environment-specific code in a clean way.
14
+ It provides a simple API to get information about the operating system,
15
+ the current Ruby interpreter, and the configured environment.
16
+ DESCRIPTION
17
+
18
+ spec.author = 'Mike Blumtritt'
19
+ spec.licenses = %w[MIT Ruby]
20
+ spec.homepage = 'https://codeberg.org/mblumtritt/host-os'
21
+ spec.metadata['source_code_uri'] = spec.homepage
22
+ spec.metadata['bug_tracker_uri'] = "#{spec.homepage}/issues"
23
+ spec.metadata['documentation_uri'] = "https://rubydoc.info/gems/host-os/#{
24
+ HostOS::VERSION
25
+ }"
26
+ spec.metadata['rubygems_mfa_required'] = 'true'
27
+ spec.metadata['yard.run'] = 'yard'
28
+
29
+ spec.required_ruby_version = '>= 3.0'
30
+
31
+ spec.files = (Dir['lib/**/*'] + Dir['examples/**/*'])
32
+ spec.files << 'host-os.gemspec' << '.yardopts'
33
+ spec.extra_rdoc_files = %w[README.md]
34
+ end
@@ -19,62 +19,51 @@ module HostOS
19
19
 
20
20
  class << self
21
21
  # @!attribute [r] mri?
22
- # @return [true, false] whether the interpreter is the Yukihiro
23
- # Matsumoto's C-based (default) Ruby Interpreter
24
- def mri?
25
- id == :mri
26
- end
22
+ # @return [true, false]
23
+ # whether the interpreter is the Yukihiro Matsumoto's C-based (default)
24
+ # Ruby Interpreter
25
+ def mri? = (@id == :mri)
27
26
  alias cruby? mri?
28
27
  alias default? mri?
29
28
 
30
29
  # @!attribute [r] cardinal?
31
- # @return [true, false] whether the interpreter is the Parrot based
32
- # Cardinal interpreter
33
- def cardinal?
34
- id == :cardinal
35
- end
30
+ # @return [true, false]
31
+ # whether the interpreter is the Parrot based Cardinal interpreter
32
+ def cardinal? = (@id == :cardinal)
36
33
  alias parrot? cardinal?
37
34
 
38
35
  # @!attribute [r] jruby?
39
- # @return [true, false] whether the interpreter is the Java based JRuby
40
- # Interpreter
41
- def jruby?
42
- id == :jruby
43
- end
36
+ # @return [true, false]
37
+ # whether the interpreter is the Java based JRuby Interpreter
38
+ def jruby? = (@id == :jruby)
44
39
  alias java? jruby?
45
40
 
46
41
  # @!attribute [r] rbx?
47
- # @return [true, false] whether the interpreter is the Rubinius
48
- # Interpreter
49
- def rbx?
50
- id == :rbx
51
- end
42
+ # @return [true, false]
43
+ # whether the interpreter is the Rubinius Interpreter
44
+ def rbx? = (@id == :rbx)
52
45
  alias rubinius? rbx?
53
46
 
54
47
  # @!attribute [r] ree?
55
- # @return [true, false] whether the interpreter is the Ruby Enterprise
56
- # Edition
57
- def ree?
58
- id == :ree
59
- end
48
+ # @return [true, false]
49
+ # whether the interpreter is the Ruby Enterprise Edition
50
+ def ree? = (@id == :ree)
60
51
  alias enterprise? ree?
61
52
 
62
53
  # @!attribute [r] jit_enabled?
63
- # @return [true, false] whether the interpreter currently uses a JIT
64
- # Compiler
65
- def jit_enabled?
66
- jit_type != :none
67
- end
54
+ # @return [true, false]
55
+ # whether the interpreter currently uses a JIT Compiler
56
+ def jit_enabled? = (jit_type != :none)
68
57
 
69
58
  # @!attribute [r] jit_type
70
- # @return [:mjit, :rjit, :yjit, :java, :none] type of currently used JIT
71
- # Compiler
72
- def jit_type
73
- return :mjit if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled?
74
- return :yjit if defined?(RubyVM::YJIT) && RubyVM::YJIT.enabled?
75
- return :rjit if defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?
76
- jruby? ? :java : :none
77
- end
59
+ # @return [:java, :mjit, :rjit, :yjit, :zjit, :none]
60
+ # type of currently used JIT Compiler
61
+ def jit_type = (@jit_type ||= find_jit_type)
62
+
63
+ # @!attribute [r] jit_modules
64
+ # @return [Array<Module>]
65
+ # available JIT Modules
66
+ def jit_modules = (@jit_modules ||= find_jit_modules)
78
67
 
79
68
  # @!visibility private
80
69
  def to_s
@@ -87,17 +76,15 @@ module HostOS
87
76
  ree: 'Enterprise Ruby',
88
77
  truffleruby: 'TruffleRuby'
89
78
  }.compare_by_identity[
90
- id
91
- ] || id.to_s.upcase
79
+ @id
80
+ ] || @id.to_s.upcase
92
81
  end
93
82
 
94
83
  # Path name of current Ruby executable.
95
84
  # @!attribute [r] exe
96
85
  # @return [String] complete path name to current Ruby executable
97
86
  # @return [nil] when executable can not be detected
98
- def exe
99
- defined?(@exe) ? @exe : @exe = find_exe
100
- end
87
+ def exe = (defined?(@exe) ? @exe : @exe = find_exe)
101
88
 
102
89
  # @!attribute [r] id
103
90
  # @return [Symbol] interpreter identifier
@@ -110,6 +97,35 @@ module HostOS
110
97
 
111
98
  private
112
99
 
100
+ def find_exe
101
+ require 'rbconfig' unless defined?(RbConfig)
102
+ RbConfig.ruby
103
+ rescue LoadError
104
+ ENV['RUBY']
105
+ rescue NoMethodError
106
+ cfg = RbConfig::CONFIG
107
+ File.join(cfg['bindir'], "#{cfg['ruby_install_name']}#{cfg['EXEEXT']}")
108
+ end
109
+
110
+ def find_jit_modules
111
+ return [] unless defined?(RubyVM)
112
+ RubyVM.constants.filter_map do |c|
113
+ c = RubyVM.const_get(c)
114
+ c if Module === c && defined?(c.reset_stats!) && defined?(c.enabled?)
115
+ end
116
+ end
117
+
118
+ def find_jit_type
119
+ return :java if jruby?
120
+ jit_modules.each do |mod|
121
+ next unless mod.enabled?
122
+ name = mod.name
123
+ idx = name.rindex(':') and name = name[(idx + 1)..]
124
+ return name.downcase.to_sym
125
+ end
126
+ :none
127
+ end
128
+
113
129
  def identify
114
130
  if defined?(RUBY_PLATFORM) && (RUBY_PLATFORM == 'parrot')
115
131
  return :cardinal
@@ -118,18 +134,6 @@ module HostOS
118
134
  return RUBY_ENGINE.to_sym if RUBY_ENGINE != 'ruby'
119
135
  RUBY_DESCRIPTION.downcase.include?('enterprise') ? :ree : :mri
120
136
  end
121
-
122
- def find_exe
123
- require 'rbconfig' unless defined?(RbConfig)
124
- RbConfig.ruby
125
- rescue LoadError
126
- ENV['RUBY']
127
- rescue NoMethodError
128
- File.join(
129
- RbConfig::CONFIG['bindir'],
130
- RbConfig::CONFIG['ruby_install_name'] + RbConfig::CONFIG['EXEEXT']
131
- )
132
- end
133
137
  end
134
138
 
135
139
  @id = identify
@@ -15,38 +15,24 @@ module HostOS
15
15
  # @return [String] name of or path to the null device
16
16
  # @note This attribute is only available on
17
17
  # Windows, OS2 and Unix systems for older Ruby versions.
18
- def dev_null
19
- File::NULL
20
- end
18
+ def dev_null = File::NULL
21
19
  elsif HostOS.windows?
22
- def dev_null
23
- 'NUL'
24
- end
20
+ def dev_null = 'NUL'
25
21
  elsif HostOS.os2?
26
- def dev_null
27
- 'nul'
28
- end
22
+ def dev_null = 'nul'
29
23
  elsif HostOS.unix?
30
- def dev_null
31
- '/dev/null'
32
- end
24
+ def dev_null = '/dev/null'
33
25
  end
34
26
 
35
27
  if HostOS.windows?
36
28
  # @attribute [r] open_command
37
29
  # @return [String] name of the open command
38
30
  # @note This attribute is only available on Windows, MacOS and Linux systems.
39
- def open_command
40
- 'start'
41
- end
31
+ def open_command = 'start'
42
32
  elsif HostOS.macosx?
43
- def open_command
44
- 'open'
45
- end
33
+ def open_command = 'open'
46
34
  elsif HostOS.linux?
47
- def open_command
48
- 'xdg-open'
49
- end
35
+ def open_command = 'xdg-open'
50
36
  end
51
37
 
52
38
  if HostOS.windows?
@@ -104,9 +90,7 @@ module HostOS
104
90
 
105
91
  # @attribute [r] temp_dir
106
92
  # @return [String] name of the temporary directory
107
- def temp_dir
108
- @temp_dir ||= find_temp_dir
109
- end
93
+ def temp_dir = (@temp_dir ||= find_temp_dir)
110
94
 
111
95
  private
112
96
 
@@ -2,5 +2,5 @@
2
2
 
3
3
  module HostOS
4
4
  # Version number of the gem.
5
- VERSION = '0.2.3'
5
+ VERSION = '0.4.0'
6
6
  end
data/lib/host-os.rb CHANGED
@@ -12,65 +12,45 @@ module HostOS
12
12
 
13
13
  # @!attribute [r] interpreter
14
14
  # @return [Interpreter] interpreter information
15
- def interpreter
16
- Interpreter
17
- end
15
+ def interpreter = Interpreter
18
16
 
19
17
  # @!attribute [r] env
20
18
  # @return [Env] environment information
21
- def env
22
- Env
23
- end
19
+ def env = Env
24
20
 
25
21
  # @!attribute [r] unix?
26
22
  # @return [true, false] whether the host OS is a Unix OS
27
- def unix?
28
- @type == :unix
29
- end
23
+ def unix? = (@type == :unix)
30
24
 
31
25
  # @!attribute [r] windows?
32
26
  # @return [true, false] whether the host OS is a Windows OS
33
- def windows?
34
- @type == :windows
35
- end
27
+ def windows? = (@type == :windows)
36
28
 
37
29
  # @!attribute [r] vms?
38
30
  # @return [true, false] whether the host OS is VMS
39
- def vms?
40
- @type == :vms
41
- end
31
+ def vms? = (@type == :vms)
42
32
 
43
33
  # @!attribute [r] os2?
44
34
  # @return [true, false] whether the host OS is OS/2
45
- def os2?
46
- @type == :os2
47
- end
35
+ def os2? = (@type == :os2)
48
36
 
49
37
  # @!attribute [r] macosx?
50
38
  # @return [true, false] whether the host OS is identified as MacOS
51
- def macosx?
52
- @id == :macosx
53
- end
39
+ def macosx? = (@id == :macosx)
54
40
 
55
41
  # @!attribute [r] linux?
56
42
  # @return [true, false] whether the host OS is identified as Linux derivate
57
- def linux?
58
- @id == :linux
59
- end
43
+ def linux? = (@id == :linux)
60
44
 
61
45
  # @!attribute [r] cygwin?
62
46
  # @return [true, false] whether the host OS is Windows/Cygwin
63
- def cygwin?
64
- @id == :cygwin
65
- end
47
+ def cygwin? = (@id == :cygwin)
66
48
 
67
49
  # @!attribute [r] posix?
68
50
  # @return [true, false] whether the host OS is Posix compatible
69
51
  # This attribute is `true` when Posix compatible commands like `fork` are
70
52
  # available.
71
- def posix?
72
- Process.respond_to?(:fork)
73
- end
53
+ def posix? = Process.respond_to?(:fork)
74
54
 
75
55
  # @param what [Symbol, String] the identifier to check
76
56
  # @return [true, false] whether the host OS is the given identifier or type
@@ -153,8 +133,7 @@ module HostOS
153
133
  def is?(what)
154
134
  return id == what if what.is_a?(Symbol)
155
135
  return id == what.to_sym if defined?(what.to_sym)
156
- return id == what.to_s.to_sym if defined?(what.to_s)
157
- false
136
+ defined?(what.to_s) ? id == what.to_s.to_sym : false
158
137
  end
159
138
 
160
139
  private
@@ -196,23 +175,26 @@ module HostOS
196
175
  extend Helper
197
176
 
198
177
  class << self
178
+ # @!attribute [r] id
179
+ # @return [Symbol]
180
+ # environment identifier
181
+
199
182
  # @!attribute [r] production?
200
- # @return [true, false] whether the environment is configured as "production"
183
+ # @return [true, false]
184
+ # whether the environment is configured as "production"
201
185
  # @note This will return true if the environment is not configured.
202
186
 
203
187
  # @!attribute [r] test?
204
188
  # @return [true, false] whether the environment is configured as "test"
205
189
 
206
190
  # @!attribute [r] development?
207
- # @return [true, false] whether the environment is configured as
208
- # "development"
209
-
210
- # @!attribute [r] id
211
- # @return [Symbol] environment identifier
191
+ # @return [true, false]
192
+ # whether the environment is configured as "development"
212
193
 
213
194
  # @!method is?(what)
214
- # @param what [Symbol, String] the identifier to check
215
- # @return [true, false] whether the environment is the given identifier
195
+ # @param what [#to_sym, #to_s] the identifier to check
196
+ # @return [true, false]
197
+ # whether the environment is the given identifier
216
198
 
217
199
  # @comment YARD requires this line
218
200
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: host-os
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Blumtritt
@@ -9,20 +9,18 @@ bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies: []
12
- description: |
13
- This gem helps you write environment-specific code in a clean way.
14
- It provides a simple API to get information about the operating system,
15
- the current Ruby interpreter, and the configured environment.
12
+ description: 'This gem helps you write environment-specific code in a clean way. It
13
+ provides a simple API to get information about the operating system, the current
14
+ Ruby interpreter, and the configured environment. '
16
15
  executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files:
19
- - LICENSE
20
18
  - README.md
21
19
  files:
22
20
  - ".yardopts"
23
- - LICENSE
24
21
  - README.md
25
22
  - examples/current.rb
23
+ - host-os.gemspec
26
24
  - lib/host-os.rb
27
25
  - lib/host-os/interpreter.rb
28
26
  - lib/host-os/support.rb
@@ -30,12 +28,14 @@ files:
30
28
  - lib/host_os.rb
31
29
  homepage: https://codeberg.org/mblumtritt/host-os
32
30
  licenses:
33
- - BSD-3-Clause
31
+ - MIT
32
+ - Ruby
34
33
  metadata:
35
- rubygems_mfa_required: 'true'
36
34
  source_code_uri: https://codeberg.org/mblumtritt/host-os
37
35
  bug_tracker_uri: https://codeberg.org/mblumtritt/host-os/issues
38
- documentation_uri: https://rubydoc.info/gems/host-os/0.2.3/HostOS
36
+ documentation_uri: https://rubydoc.info/gems/host-os/0.4.0
37
+ rubygems_mfa_required: 'true'
38
+ yard.run: yard
39
39
  rdoc_options: []
40
40
  require_paths:
41
41
  - lib
@@ -43,14 +43,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- version: '2.7'
46
+ version: '3.0'
47
47
  required_rubygems_version: !ruby/object:Gem::Requirement
48
48
  requirements:
49
49
  - - ">="
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  requirements: []
53
- rubygems_version: 3.7.1
53
+ rubygems_version: 4.0.11
54
54
  specification_version: 4
55
55
  summary: This module offers details on the host OS, the present Ruby interpreter and
56
56
  environment.
data/LICENSE DELETED
@@ -1,28 +0,0 @@
1
- BSD 3-Clause License
2
-
3
- Copyright (c) 2017-2025, Mike Blumtritt. All rights reserved.
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are met:
7
-
8
- 1. Redistributions of source code must retain the above copyright notice, this
9
- list of conditions and the following disclaimer.
10
-
11
- 2. Redistributions in binary form must reproduce the above copyright notice,
12
- this list of conditions and the following disclaimer in the documentation
13
- and/or other materials provided with the distribution.
14
-
15
- 3. Neither the name of the copyright holder nor the names of its
16
- contributors may be used to endorse or promote products derived from
17
- this software without specific prior written permission.
18
-
19
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.