Class: Mongo::Server::AppMetadata::Platform Private
| 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.
Constant Summary
-
ENGINE_NAMES =
# File 'lib/mongo/server/app_metadata/platform.rb', line 51
{ 'jruby' => 'JRuby', 'truffleruby' => 'TruffleRuby' }.freeze
Class Method Summary
-
.new(metadata) ⇒ Platform
constructor
Internal use only
Create a new
Platformobject, referencing the given metadata object.
Instance Attribute Summary
-
#jruby? ⇒ true | false
readonly
Internal use only
Queries whether the current runtime is JRuby or not.
- #metadata ⇒ Mongo::Server::AppMetadata readonly Internal use only
-
#mri? ⇒ true | false
readonly
Internal use only
Queries whether the current runtime is Ruby MRI or not.
Instance Method Summary
-
#default_platform_list ⇒ Array<String>
Internal use only
Builds and returns the default platform list, for use when building the platform string.
- #engine_name Internal use only
-
#java_version ⇒ String | nil
Internal use only
Returns the version of the current Java environment, or nil if not invoked with JRuby.
-
#platforms ⇒ Array<String>
Internal use only
Returns the list of platform identifiers that identify this runtime.
-
#purpose ⇒ String | nil
Internal use only
Returns a single letter representing the purpose reported to the metadata, or nil if no purpose was specified.
-
#ruby_versions ⇒ Array<String>
Internal use only
Returns the list of Ruby versions that identify this runtime.
-
#to_s ⇒ String
Internal use only
Builds and returns the platform string by concatenating relevant values together.
Instance Attribute Details
#jruby? ⇒ true | false (readonly)
Queries whether the current runtime is JRuby or not.
# File 'lib/mongo/server/app_metadata/platform.rb', line 47
def jruby? RUBY_ENGINE == 'jruby' end
#metadata ⇒ Mongo::Server::AppMetadata (readonly)
# File 'lib/mongo/server/app_metadata/platform.rb', line 27
attr_reader :
#mri? ⇒ true | false (readonly)
Queries whether the current runtime is Ruby MRI or not.
# File 'lib/mongo/server/app_metadata/platform.rb', line 40
def mri? RUBY_ENGINE == 'ruby' end
Instance Method Details
#default_platform_list ⇒ Array<String>
Builds and returns the default platform list, for use when building the platform string.
# File 'lib/mongo/server/app_metadata/platform.rb', line 91
def default_platform_list [ .platform, *ruby_versions, *platforms, RbConfig::CONFIG['build'] ] end
#engine_name
# File 'lib/mongo/server/app_metadata/platform.rb', line 53
def engine_name ENGINE_NAMES[RUBY_ENGINE] || RUBY_ENGINE end
#java_version ⇒ String | nil
Returns the version of the current Java environment, or nil if not invoked with JRuby.
# 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
#platforms ⇒ Array<String>
Returns the list of platform identifiers that identify this runtime.
# 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
Returns a single letter representing the purpose reported to the metadata, or nil if no purpose was specified.
# 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>
Returns the list of Ruby versions that identify this runtime.
# 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
Builds and returns the platform string by concatenating relevant values together.
# 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