Class: Vagrant::Util::Experimental
- Inherits:
-
Object
- Object
- Vagrant::Util::Experimental
- Defined in:
- lib/vagrant/util/experimental.rb
Class Method Summary collapse
-
.enabled? ⇒ Boolean
A method for determining if the experimental flag has been enabled with any features.
-
.feature_enabled?(feature) ⇒ Boolean
A method for Vagrant internals to determine if a given feature has been abled by the user, is a valid feature flag and can be used.
-
.features_requested ⇒ Array
Returns the features requested for the experimental flag.
-
.global_enabled? ⇒ Boolean
A method for determining if all experimental features have been enabled by either a global enabled value "1" or all features explicitly enabled.
-
.guard_with(*features, &block) ⇒ Object
A function to guard experimental blocks of code from being executed.
-
.reset! ⇒ Object
Reset the cached values for platform.
Class Method Details
.enabled? ⇒ Boolean
A method for determining if the experimental flag has been enabled with any features
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vagrant/util/experimental.rb', line 12 def enabled? if !defined?(@_experimental) experimental = features_requested if experimental.size >= 1 && experimental.first != "0" @_experimental = true else @_experimental = false end end @_experimental end |
.feature_enabled?(feature) ⇒ Boolean
A method for Vagrant internals to determine if a given feature has been abled by the user, is a valid feature flag and can be used.
45 46 47 48 49 50 |
# File 'lib/vagrant/util/experimental.rb', line 45 def feature_enabled?(feature) experimental = features_requested feature = feature.to_s return global_enabled? || experimental.include?(feature) end |
.features_requested ⇒ Array
Returns the features requested for the experimental flag
55 56 57 58 59 60 |
# File 'lib/vagrant/util/experimental.rb', line 55 def features_requested if !defined?(@_requested_features) @_requested_features = ENV["VAGRANT_EXPERIMENTAL"].to_s.downcase.split(',') end @_requested_features end |
.global_enabled? ⇒ Boolean
A method for determining if all experimental features have been enabled by either a global enabled value "1" or all features explicitly enabled.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vagrant/util/experimental.rb', line 28 def global_enabled? if !defined?(@_global_enabled) experimental = features_requested if experimental.size == 1 && experimental.first == "1" @_global_enabled = true else @_global_enabled = false end end @_global_enabled end |
.guard_with(*features, &block) ⇒ Object
A function to guard experimental blocks of code from being executed
66 67 68 |
# File 'lib/vagrant/util/experimental.rb', line 66 def guard_with(*features, &block) yield if block_given? && features.any? {|f| feature_enabled?(f)} end |
.reset! ⇒ Object
Reset the cached values for platform. This is not considered a public API and should only be used for testing.
73 74 75 |
# File 'lib/vagrant/util/experimental.rb', line 73 def reset! instance_variables.each(&method(:remove_instance_variable)) end |