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

Inherits:
Object
  • Object
show all
Defined in:
build/ruby-driver-v2.19/lib/mongo/server/app_metadata/platform.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

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

Since:

  • 2.0.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(metadata) ⇒ Platform

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Parameters:

Since:

  • 2.0.0



33
34
35
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/platform.rb', line 33

def initialize()
  @metadata = 
end

Instance Attribute Details

#metadataMongo::Server::AppMetadata (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the metadata object to reference when building the platform string.

Returns:

Since:

  • 2.0.0



27
28
29
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/platform.rb', line 27

def 
  @metadata
end

Instance Method Details

#default_platform_listArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



78
79
80
81
82
83
84
85
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/platform.rb', line 78

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

#java_versionString | nil

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



68
69
70
71
72
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/platform.rb', line 68

def java_version
  return nil unless jruby?

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

#jruby?true | false

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Queries whether the current runtime is JRuby or not.

Returns:

  • (true | false)

    whether the runtime is JRuby or not.

Since:

  • 2.0.0



40
41
42
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/platform.rb', line 40

def jruby?
  BSON::Environment.jruby?
end

#platformsArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the list of platform identifiers that identify this runtime.

Returns:

  • (Array<String>)

    the list of platform identifiers.

Since:

  • 2.0.0



58
59
60
61
62
# File 'build/ruby-driver-v2.19/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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



91
92
93
94
95
# File 'build/ruby-driver-v2.19/lib/mongo/server/app_metadata/platform.rb', line 91

def purpose
  return nil unless .purpose

  .purpose.to_s[0].upcase
end

#ruby_versionsArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns the list of Ruby versions that identify this runtime.

Returns:

  • (Array<String>)

    the list of ruby versions

Since:

  • 2.0.0



47
48
49
50
51
52
53
# File 'build/ruby-driver-v2.19/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

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Returns:

  • (String)

    the platform string

Since:

  • 2.0.0



101
102
103
104
105
106
107
108
109
110
# File 'build/ruby-driver-v2.19/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