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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(feature_name, feature_yaml_opts) ⇒ Feature

Returns a new instance of Feature.



11
12
13
14
15
16
# File 'lib/inspec/feature.rb', line 11

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"]
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

Instance Method Details

#env_preview_valueObject



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

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)


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

def no_preview?
  env_preview.nil?
end

#previewable?Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/inspec/feature.rb', line 18

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