Class: RubyWasm::FeatureSet

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_wasm/feature_set.rb,
sig/ruby_wasm/feature_set.rbs

Overview

A set of feature flags that can be used to enable or disable experimental features.

Constant Summary collapse

FEATURES =

Maps the feature to the environment variable.

Returns:

  • (Hash[Symbol, String])
{
  dynamic_linking: "RUBY_WASM_EXPERIMENTAL_DYNAMIC_LINKING",
  component_model: "RUBY_WASM_EXPERIMENTAL_COMPONENT_MODEL",
}.freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(features) ⇒ FeatureSet

Returns a new instance of FeatureSet.

Parameters:

  • (Hash[Symbol, bool])


4
5
6
# File 'lib/ruby_wasm/feature_set.rb', line 4

def initialize(features)
  @features = features
end

Class Method Details

.derive_from_envRubyWasm::FeatureSet

Derives the feature set from the environment variables. A feature is enabled if the corresponding environment variable is set to "1", otherwise it is disabled.



18
19
20
21
# File 'lib/ruby_wasm/feature_set.rb', line 18

def self.derive_from_env
  values = FEATURES.transform_values { |key| ENV[key] == "1" }
  new(values)
end

Instance Method Details

#support_component_model?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/ruby_wasm/feature_set.rb', line 27

def support_component_model?
  @features[:component_model] || @features[:dynamic_linking]
end

#support_dynamic_linking?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/ruby_wasm/feature_set.rb', line 23

def support_dynamic_linking?
  @features[:dynamic_linking]
end