class Vagrant::Util::Experimental

Public Class Methods

enabled?() click to toggle source

A method for determining if the experimental flag has been enabled with any features

@return [Boolean]

# File lib/vagrant/util/experimental.rb, line 9
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) click to toggle source

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.

@param [String] feature @return [Boolean] - A hash containing the original array and if it is valid

# File lib/vagrant/util/experimental.rb, line 42
def feature_enabled?(feature)
  experimental = features_requested
  feature = feature.to_s

  return global_enabled? || experimental.include?(feature)
end
features_requested() click to toggle source

Returns the features requested for the experimental flag

@return [Array] - Returns an array of requested experimental features

# File lib/vagrant/util/experimental.rb, line 52
def features_requested
  if !defined?(@_requested_features)
    @_requested_features = ENV["VAGRANT_EXPERIMENTAL"].to_s.downcase.split(',')
  end
  @_requested_features
end
global_enabled?() click to toggle source

A method for determining if all experimental features have been enabled by either a global enabled value “1” or all features explicitly enabled.

@return [Boolean]

# File lib/vagrant/util/experimental.rb, line 25
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) { || ... } click to toggle source

A function to guard experimental blocks of code from being executed

@param [Array] features - Array of features to guard a method with @param [Block] block - Block of ruby code to be guarded against

# File lib/vagrant/util/experimental.rb, line 63
def guard_with(*features, &block)
  yield if block_given? && features.any? {|f| feature_enabled?(f)}
end
reset!() click to toggle source

@private Reset the cached values for platform. This is not considered a public API and should only be used for testing.

# File lib/vagrant/util/experimental.rb, line 70
def reset!
  instance_variables.each(&method(:remove_instance_variable))
end