Class: Mongo::Server::AppMetadata::Platform Private
- Inherits:
-
Object
- Object
- Mongo::Server::AppMetadata::Platform
- Defined in:
- 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.
Constant Summary collapse
- ENGINE_NAMES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ 'jruby' => 'JRuby', 'truffleruby' => 'TruffleRuby' }.freeze
Instance Attribute Summary collapse
-
#metadata ⇒ Mongo::Server::AppMetadata
readonly
private
The metadata object to reference when building the platform string.
Instance Method Summary collapse
-
#default_platform_list ⇒ Array<String>
private
Builds and returns the default platform list, for use when building the platform string.
- #engine_name ⇒ Object private
-
#initialize(metadata) ⇒ Platform
constructor
private
Create a new Platform object, referencing the given metadata object.
-
#java_version ⇒ String | nil
private
Returns the version of the current Java environment, or nil if not invoked with JRuby.
-
#jruby? ⇒ true | false
private
Queries whether the current runtime is JRuby or not.
-
#mri? ⇒ true | false
private
Queries whether the current runtime is Ruby MRI or not.
-
#platforms ⇒ Array<String>
private
Returns the list of platform identifiers that identify this runtime.
-
#purpose ⇒ String | nil
private
Returns a single letter representing the purpose reported to the metadata, or nil if no purpose was specified.
-
#ruby_versions ⇒ Array<String>
private
Returns the list of Ruby versions that identify this runtime.
-
#to_s ⇒ String
private
Builds and returns the platform string by concatenating relevant values together.
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.
33 34 35 |
# File 'lib/mongo/server/app_metadata/platform.rb', line 33 def initialize() @metadata = end |
Instance Attribute Details
#metadata ⇒ Mongo::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.
27 28 29 |
# File 'lib/mongo/server/app_metadata/platform.rb', line 27 def @metadata end |
Instance Method Details
#default_platform_list ⇒ Array<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.
91 92 93 94 95 96 97 98 |
# File 'lib/mongo/server/app_metadata/platform.rb', line 91 def default_platform_list [ .platform, *ruby_versions, *platforms, RbConfig::CONFIG['build'] ] end |
#engine_name ⇒ Object
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.
53 54 55 |
# File 'lib/mongo/server/app_metadata/platform.rb', line 53 def engine_name ENGINE_NAMES[RUBY_ENGINE] || RUBY_ENGINE end |
#java_version ⇒ String | 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.
81 82 83 84 85 |
# File 'lib/mongo/server/app_metadata/platform.rb', line 81 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.
47 48 49 |
# File 'lib/mongo/server/app_metadata/platform.rb', line 47 def jruby? RUBY_ENGINE == 'jruby' end |
#mri? ⇒ 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 Ruby MRI or not.
40 41 42 |
# File 'lib/mongo/server/app_metadata/platform.rb', line 40 def mri? RUBY_ENGINE == 'ruby' end |
#platforms ⇒ Array<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.
71 72 73 74 75 |
# File 'lib/mongo/server/app_metadata/platform.rb', line 71 def platforms [ RUBY_PLATFORM ].tap do |list| list.push "JVM #{java_version}" if jruby? end end |
#purpose ⇒ String | 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.
104 105 106 107 108 |
# File 'lib/mongo/server/app_metadata/platform.rb', line 104 def purpose return nil unless .purpose .purpose.to_s[0].upcase end |
#ruby_versions ⇒ Array<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.
60 61 62 63 64 65 66 |
# File 'lib/mongo/server/app_metadata/platform.rb', line 60 def ruby_versions if mri? [ "Ruby #{RUBY_VERSION}" ] else [ "#{engine_name} #{RUBY_ENGINE_VERSION}", "like Ruby #{RUBY_VERSION}" ] end end |
#to_s ⇒ 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 platform string by concatenating relevant values together.
114 115 116 117 118 119 120 121 122 123 |
# File 'lib/mongo/server/app_metadata/platform.rb', line 114 def to_s primary = [ *default_platform_list, purpose ].compact.join(', ') list = [ primary ] .wrapping_libraries&.each do |library| list << (library[:platform] || '') end list.join('|') end |