Class: Inspec::Feature

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/feature.rb,
lib/inspec/feature/config.rb,
lib/inspec/feature/runner.rb

Defined Under Namespace

Classes: Config, Runner

Constant Summary collapse

@@features_invoked =
[]

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature_name, feature_yaml_opts) ⇒ Feature

Returns a new instance of Feature.



14
15
16
17
18
19
20
# File 'lib/inspec/feature.rb', line 14

def initialize(feature_name, feature_yaml_opts)
  @name = feature_name
  feature_yaml_opts ||= {}
  @description = feature_yaml_opts["description"]
  @env_preview = feature_yaml_opts["env_preview"]
  @@features_invoked << feature_name
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



10
11
12
# File 'lib/inspec/feature.rb', line 10

def description
  @description
end

#env_previewObject (readonly)

Returns the value of attribute env_preview.



10
11
12
# File 'lib/inspec/feature.rb', line 10

def env_preview
  @env_preview
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/inspec/feature.rb', line 10

def name
  @name
end

Class Method Details

.list_all_invoked_featuresObject



38
39
40
# File 'lib/inspec/feature.rb', line 38

def self.list_all_invoked_features
  @@features_invoked.uniq
end

Instance Method Details

#env_preview_valueObject



31
32
33
34
35
36
# File 'lib/inspec/feature.rb', line 31

def env_preview_value
  # Examples: If feature name is "inspec-test-feature"
  # ENV used for this feature preview would be CHEF_PREVIEW_TEST_FEATURE
  env_preview_feature_name = name.to_s.split("inspec-")[-1]
  ENV["CHEF_PREVIEW_#{env_preview_feature_name.gsub("-", "_").upcase}"]
end

#no_preview?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/inspec/feature.rb', line 27

def no_preview?
  env_preview.nil?
end

#previewable?Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/inspec/feature.rb', line 22

def previewable?
  # If the feature is previewable in config (features.yaml) & has an environment value set to use previewed feature
  !!env_preview && !env_preview_value.nil?
end