PHP 8.2.31
Preview: platform.rb Size: 6.05 KB
//proc/thread-self/root/opt/alt/ruby21/lib64/ruby/2.1.0/rubygems/platform.rb

require "rubygems/deprecate"

##
# Available list of platforms for targeting Gem installations.
#
# See `gem help platform` for information on platform matching.

class Gem::Platform

  @local = nil

  attr_accessor :cpu

  attr_accessor :os

  attr_accessor :version

  def self.local
    arch = RbConfig::CONFIG['arch']
    arch = "#{arch}_60" if arch =~ /mswin32$/
    @local ||= new(arch)
  end

  def self.match(platform)
    Gem.platforms.any? do |local_platform|
      platform.nil? or
        local_platform == platform or
        (local_platform != Gem::Platform::RUBY and local_platform =~ platform)
    end
  end

  def self.installable?(spec)
    if spec.respond_to? :installable_platform?
      spec.installable_platform?
    else
      match spec.platform
    end
  end

  def self.new(arch) # :nodoc:
    case arch
    when Gem::Platform::CURRENT then
      Gem::Platform.local
    when Gem::Platform::RUBY, nil, '' then
      Gem::Platform::RUBY
    else
      super
    end
  end

  def initialize(arch)
    case arch
    when Array then
      @cpu, @os, @version = arch
    when String then
      arch = arch.split '-'

      if arch.length > 2 and arch.last !~ /\d/ then # reassemble x86-linux-gnu
        extra = arch.pop
        arch.last << "-#{extra}"
      end

      cpu = arch.shift

      @cpu = case cpu
             when /i\d86/ then 'x86'
             else cpu
             end

      if arch.length == 2 and arch.last =~ /^\d+(\.\d+)?$/ then # for command-line
        @os, @version = arch
        return
      end

      os, = arch
      @cpu, os = nil, cpu if os.nil? # legacy jruby

      @os, @version = case os
                      when /aix(\d+)?/ then             [ 'aix',       $1  ]
                      when /cygwin/ then                [ 'cygwin',    nil ]
                      when /darwin(\d+)?/ then          [ 'darwin',    $1  ]
                      when /^macruby$/ then             [ 'macruby',   nil ]
                      when /freebsd(\d+)?/ then         [ 'freebsd',   $1  ]
                      when /hpux(\d+)?/ then            [ 'hpux',      $1  ]
                      when /^java$/, /^jruby$/ then     [ 'java',      nil ]
                      when /^java([\d.]*)/ then         [ 'java',      $1  ]
                      when /^dalvik(\d+)?$/ then        [ 'dalvik',    $1  ]
                      when /^dotnet$/ then              [ 'dotnet',    nil ]
                      when /^dotnet([\d.]*)/ then       [ 'dotnet',    $1  ]
                      when /linux/ then                 [ 'linux',     $1  ]
                      when /mingw32/ then               [ 'mingw32',   nil ]
                      when /(mswin\d+)(\_(\d+))?/ then
                        os, version = $1, $3
                        @cpu = 'x86' if @cpu.nil? and os =~ /32$/
                        [os, version]
                      when /netbsdelf/ then             [ 'netbsdelf', nil ]
                      when /openbsd(\d+\.\d+)?/ then    [ 'openbsd',   $1  ]
                      when /solaris(\d+\.\d+)?/ then    [ 'solaris',   $1  ]
                      # test
                      when /^(\w+_platform)(\d+)?/ then [ $1,          $2  ]
                      else                              [ 'unknown',   nil ]
                      end
    when Gem::Platform then
      @cpu = arch.cpu
      @os = arch.os
      @version = arch.version
    else
      raise ArgumentError, "invalid argument #{arch.inspect}"
    end
  end

  def inspect
    "#<%s:0x%x @cpu=%p, @os=%p, @version=%p>" % [self.class, object_id, *to_a]
  end

  def to_a
    [@cpu, @os, @version]
  end

  def to_s
    to_a.compact.join '-'
  end

  ##
  # Is +other+ equal to this platform?  Two platforms are equal if they have
  # the same CPU, OS and version.

  def ==(other)
    self.class === other and to_a == other.to_a
  end

  alias :eql? :==

  def hash # :nodoc:
    to_a.hash
  end

  ##
  # Does +other+ match this platform?  Two platforms match if they have the
  # same CPU, or either has a CPU of 'universal', they have the same OS, and
  # they have the same version, or either has no version.
  #
  # Additionally, the platform will match if the local CPU is 'arm' and the
  # other CPU starts with "arm" (for generic ARM family support).

  def ===(other)
    return nil unless Gem::Platform === other

    # cpu
    (@cpu == 'universal' or other.cpu == 'universal' or @cpu == other.cpu or
     (@cpu == 'arm' and other.cpu =~ /\Aarm/)) and

    # os
    @os == other.os and

    # version
    (@version.nil? or other.version.nil? or @version == other.version)
  end

  ##
  # Does +other+ match this platform?  If +other+ is a String it will be
  # converted to a Gem::Platform first.  See #=== for matching rules.

  def =~(other)
    case other
    when Gem::Platform then # nop
    when String then
      # This data is from http://gems.rubyforge.org/gems/yaml on 19 Aug 2007
      other = case other
              when /^i686-darwin(\d)/     then ['x86',       'darwin',  $1    ]
              when /^i\d86-linux/         then ['x86',       'linux',   nil   ]
              when 'java', 'jruby'        then [nil,         'java',    nil   ]
              when /^dalvik(\d+)?$/       then [nil,         'dalvik',  $1    ]
              when /dotnet(\-(\d+\.\d+))?/ then ['universal','dotnet',  $2    ]
              when /mswin32(\_(\d+))?/    then ['x86',       'mswin32', $2    ]
              when 'powerpc-darwin'       then ['powerpc',   'darwin',  nil   ]
              when /powerpc-darwin(\d)/   then ['powerpc',   'darwin',  $1    ]
              when /sparc-solaris2.8/     then ['sparc',     'solaris', '2.8' ]
              when /universal-darwin(\d)/ then ['universal', 'darwin',  $1    ]
              else                             other
              end

      other = Gem::Platform.new other
    else
      return nil
    end

    self === other
  end

  ##
  # A pure-Ruby gem that may use Gem::Specification#extensions to build
  # binary files.

  RUBY = 'ruby'

  ##
  # A platform-specific gem that is built for the packaging Ruby's platform.
  # This will be replaced with Gem::Platform::local.

  CURRENT = 'current'
end

Directory Contents

Dirs: 10 × Files: 59

Name Size Perms Modified Actions
commands DIR
- drwxr-xr-x 2024-03-03 22:43:11
Edit Download
core_ext DIR
- drwxr-xr-x 2024-03-03 22:43:11
Edit Download
ext DIR
- drwxr-xr-x 2024-03-03 22:43:11
Edit Download
package DIR
- drwxr-xr-x 2024-03-03 22:43:11
Edit Download
- drwxr-xr-x 2024-03-03 22:43:11
Edit Download
resolver DIR
- drwxr-xr-x 2024-03-03 22:43:11
Edit Download
security DIR
- drwxr-xr-x 2024-03-03 22:43:11
Edit Download
source DIR
- drwxr-xr-x 2024-03-03 22:43:11
Edit Download
ssl_certs DIR
- drwxr-xr-x 2024-03-03 22:43:11
Edit Download
util DIR
- drwxr-xr-x 2024-03-03 22:43:11
Edit Download
3.00 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
5.65 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
13.43 KB lrw-r--r-- 2012-11-30 16:27:52
Edit Download
4.62 KB lrw-r--r-- 2013-09-14 08:59:02
Edit Download
1.67 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
12.23 KB lrw-r--r-- 2023-07-26 14:19:40
Edit Download
3.64 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
7.77 KB lrw-r--r-- 2013-09-14 08:59:02
Edit Download
12.64 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
5.53 KB lrw-r--r-- 2013-02-27 23:20:57
Edit Download
1.70 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
3.04 KB lrw-r--r-- 2013-11-21 23:27:30
Edit Download
2.42 KB lrw-r--r-- 2013-11-19 00:34:13
Edit Download
5.87 KB lrw-r--r-- 2013-11-21 23:27:30
Edit Download
431 B lrw-r--r-- 2013-10-16 06:00:39
Edit Download
3.97 KB lrw-r--r-- 2013-09-18 21:29:41
Edit Download
1.96 KB lrw-r--r-- 2013-09-14 08:59:02
Edit Download
13.03 KB lrw-r--r-- 2013-10-16 00:14:16
Edit Download
21.42 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
4.20 KB lrw-r--r-- 2023-07-26 14:19:40
Edit Download
307 B lrw-r--r-- 2013-07-09 23:21:36
Edit Download
281 B lrw-r--r-- 2012-11-29 06:52:18
Edit Download
5.21 KB lrw-r--r-- 2013-09-14 08:59:02
Edit Download
3.36 KB lrw-r--r-- 2011-07-27 01:40:07
Edit Download
1.35 KB lrw-r--r-- 2012-11-29 06:52:18
Edit Download
2.23 KB lrw-r--r-- 2013-09-14 08:59:02
Edit Download
14.25 KB lrw-r--r-- 2023-07-26 14:19:40
Edit Download
3.77 KB lrw-r--r-- 2013-08-26 20:24:51
Edit Download
1.82 KB lrw-r--r-- 2013-09-14 08:59:02
Edit Download
6.05 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
269 B lrw-r--r-- 2013-10-20 01:33:19
Edit Download
763 B lrw-r--r-- 2013-07-09 22:34:58
Edit Download
7.75 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
9.46 KB lrw-r--r-- 2015-08-18 12:56:58
Edit Download
7.53 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
6.94 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
6.10 KB lrw-r--r-- 2013-12-08 01:22:39
Edit Download
12.46 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
1.11 KB lrw-r--r-- 2023-07-26 14:19:40
Edit Download
20.96 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
21.69 KB lrw-r--r-- 2013-11-10 17:51:40
Edit Download
4.90 KB lrw-r--r-- 2013-12-08 01:22:39
Edit Download
2.47 KB lrw-r--r-- 2013-11-19 00:34:13
Edit Download
111 B lrw-r--r-- 2013-09-14 08:59:02
Edit Download
93 B lrw-r--r-- 2013-09-14 08:59:02
Edit Download
70.80 KB lrw-r--r-- 2023-07-26 14:19:40
Edit Download
6.40 KB lrw-r--r-- 2013-11-19 00:34:13
Edit Download
3.10 KB lrw-r--r-- 2013-10-18 21:56:18
Edit Download
2.09 KB lrw-r--r-- 2013-12-19 22:09:19
Edit Download
35.62 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
8.37 KB lrw-r--r-- 2013-12-08 01:22:39
Edit Download
1.23 KB lrw-r--r-- 2011-07-27 01:40:07
Edit Download
8.69 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
762 B lrw-r--r-- 2013-10-20 01:33:19
Edit Download
14.40 KB lrw-r--r-- 2013-12-13 00:51:04
Edit Download
2.26 KB lrw-r--r-- 2013-11-25 19:14:49
Edit Download
4.18 KB lrw-r--r-- 2013-11-30 23:27:52
Edit Download
10.78 KB lrw-r--r-- 2014-02-06 02:59:36
Edit Download
1.83 KB lrw-r--r-- 2013-09-14 08:59:02
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).