123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Server::AppMetadata::Platform Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/mongo/server/app_metadata/platform.rb

Overview

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

Since:

  • 2.0.0

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#jruby?true | false (readonly)

Queries whether the current runtime is JRuby or not.

Returns:

  • (true | false)

    whether the runtime is JRuby or not.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server/app_metadata/platform.rb', line 40

def jruby?
  BSON::Environment.jruby?
end

#metadataMongo::Server::AppMetadata (readonly)

Returns:

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server/app_metadata/platform.rb', line 27

attr_reader :

Instance Method Details

#default_platform_listArray<String>

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

Returns:

  • (Array<String>)

    the list of platform identifiers

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server/app_metadata/platform.rb', line 78

def default_platform_list
  [
    .platform,
    *ruby_versions,
    *platforms,
    RbConfig::CONFIG['build']
  ]
end

#java_versionString | nil

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

Returns:

  • (String | nil)

    the current Java version

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server/app_metadata/platform.rb', line 68

def java_version
  return nil unless jruby?

  java.lang.System.get_property('java.version')
end

#platformsArray<String>

Returns the list of platform identifiers that identify this runtime.

Returns:

  • (Array<String>)

    the list of platform identifiers.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server/app_metadata/platform.rb', line 58

def platforms
  [ RUBY_PLATFORM ].tap do |list|
    list.push "JVM #{java_version}" if jruby?
  end
end

#purposeString | nil

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

Returns:

  • (String | nil)

    the code representing the purpose

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server/app_metadata/platform.rb', line 91

def purpose
  return nil unless .purpose

  .purpose.to_s[0].upcase
end

#ruby_versionsArray<String>

Returns the list of Ruby versions that identify this runtime.

Returns:

  • (Array<String>)

    the list of ruby versions

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server/app_metadata/platform.rb', line 47

def ruby_versions
  if jruby?
    [ "JRuby #{JRUBY_VERSION}", "like Ruby #{RUBY_VERSION}" ]
  else
    [ "Ruby #{RUBY_VERSION}" ]
  end
end

#to_sString

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

Returns:

  • (String)

    the platform string

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/server/app_metadata/platform.rb', line 101

def to_s
  primary = [ *default_platform_list, purpose ].compact.join(', ')
  list = [ primary ]

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

  list.join('|')
end