Class: Vagrant::Util::Experimental

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/util/experimental.rb

Class Method Summary collapse

Class Method Details

.enabled?Boolean

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

Returns:

  • (Boolean)


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.

Parameters:

  • feature (String)

Returns:

  • (Boolean)
    • A hash containing the original array and if it is valid


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_requestedArray

Returns the features requested for the experimental flag

Returns:

  • (Array)
    • Returns an array of requested experimental features


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.

Returns:

  • (Boolean)


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

Parameters:

  • features (Array)
    • Array of features to guard a method with
  • block (Block)
    • Block of ruby code to be guarded against


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