Class: Inspec::Input::NO_VALUE_SET

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/objects/input.rb

Overview

This special class is used to represent the value when an input has not been assigned a value. This allows a user to explicitly assign nil to an input.

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ NO_VALUE_SET

rubocop: disable Style/ClassAndModuleCamelCase



21
22
23
24
25
26
27
28
29
30
# File 'lib/inspec/objects/input.rb', line 21

def initialize(name)
  @name = name

  # output warn message if we are in a exec call
  Inspec::Log.warn(
    "Input '#{@name}' does not have a value. "\
    "Use --input-file to provide a value for '#{@name}' or specify a  "\
    "value with `attribute('#{@name}', value: 'somevalue', ...)`.",
  ) if Inspec::BaseCLI.inspec_cli_command == :exec
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*_) ⇒ Object



32
33
34
# File 'lib/inspec/objects/input.rb', line 32

def method_missing(*_)
  self
end

Instance Method Details

#is_a?(klass) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
47
48
49
50
51
# File 'lib/inspec/objects/input.rb', line 44

def is_a?(klass)
  if klass == Inspec::Attribute::DEFAULT_ATTRIBUTE
    Inspec.deprecate(:rename_attributes_to_inputs, "Don't check for `is_a?(Inspec::Attribute::DEFAULT_ATTRIBUTE)`, check for `Inspec::Input::NO_VALUE_SET")
    true # lie for backward compatibility
  else
    super(klass)
  end
end

#kind_of?(klass) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
60
# File 'lib/inspec/objects/input.rb', line 53

def kind_of?(klass)
  if klass == Inspec::Attribute::DEFAULT_ATTRIBUTE
    Inspec.deprecate(:rename_attributes_to_inputs, "Don't check for `kind_of?(Inspec::Attribute::DEFAULT_ATTRIBUTE)`, check for `Inspec::Input::NO_VALUE_SET")
    true # lie for backward compatibility
  else
    super(klass)
  end
end

#respond_to_missing?(_, _) ⇒ Boolean

Returns:

  • (Boolean)


36
37
38
# File 'lib/inspec/objects/input.rb', line 36

def respond_to_missing?(_, _)
  true
end

#to_sObject



40
41
42
# File 'lib/inspec/objects/input.rb', line 40

def to_s
  "Input '#{@name}' does not have a value. Skipping test."
end