class Mongo::Server::AppMetadata::Platform

Implements the logic for building the platform string for the handshake.

@api private

Attributes

metadata[R]

@return [ Mongo::Server::AppMetadata ] the metadata object to

reference when building the platform string.

Public Class Methods

new(metadata) click to toggle source

Create a new Platform object, referencing the given metadata object.

@param [ Mongo::Server::AppMetadata ] metadata the metadata object

the reference when building the platform string.
# File lib/mongo/server/app_metadata/platform.rb, line 32
def initialize(metadata)
  @metadata = metadata
end

Public Instance Methods

default_platform_list() click to toggle source

Builds and returns the default platform list, for use when building the platform string.

@return [ Array<String> ] the list of platform identifiers

# File lib/mongo/server/app_metadata/platform.rb, line 77
def default_platform_list
  [
    metadata.platform,
    *ruby_versions,
    *platforms,
    RbConfig::CONFIG['build']
  ]
end
java_version() click to toggle source

Returns the version of the current Java environment, or nil if not invoked with JRuby.

@return [ String | nil ] the current Java version

# File lib/mongo/server/app_metadata/platform.rb, line 67
def java_version
  return nil unless jruby?

  java.lang.System.get_property('java.version')
end
jruby?() click to toggle source

Queries whether the current runtime is JRuby or not.

@return [ true | false ] whether the runtime is JRuby or not.

# File lib/mongo/server/app_metadata/platform.rb, line 39
def jruby?
  BSON::Environment.jruby?
end
platforms() click to toggle source

Returns the list of platform identifiers that identify this runtime.

@return [ Array<String> ] the list of platform identifiers.

# File lib/mongo/server/app_metadata/platform.rb, line 57
def platforms
  [ RUBY_PLATFORM ].tap do |list|
    list.push "JVM #{java_version}" if jruby?
  end
end
purpose() click to toggle source

Returns a single letter representing the purpose reported to the metadata, or nil if no purpose was specified.

@return [ String | nil ] the code representing the purpose

# File lib/mongo/server/app_metadata/platform.rb, line 90
def purpose
  return nil unless metadata.purpose

  metadata.purpose.to_s[0].upcase
end
ruby_versions() click to toggle source

Returns the list of Ruby versions that identify this runtime.

@return [ Array<String> ] the list of ruby versions

# File lib/mongo/server/app_metadata/platform.rb, line 46
def ruby_versions
  if jruby?
    [ "JRuby #{JRUBY_VERSION}", "like Ruby #{RUBY_VERSION}" ]
  else
    [ "Ruby #{RUBY_VERSION}" ]
  end
end
to_s() click to toggle source

Builds and returns the platform string by concatenating relevant values together.

@return [ String ] the platform string

# File lib/mongo/server/app_metadata/platform.rb, line 100
def to_s
  primary = [ *default_platform_list, purpose ].compact.join(', ')
  list = [ primary ]

  metadata.wrapping_libraries&.each do |library|
    list << (library[:platform] || '')
  end

  list.join('|')
end