Class: Inspec::Input::NO_VALUE_SET

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

Overview

#
Class NO_VALUE_SET
#

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, warn_on_create = true) ⇒ NO_VALUE_SET

rubocop: disable Naming/ClassAndModuleCamelCase



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/inspec/input.rb', line 101

def initialize(name, warn_on_create = true)
  @name = name

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

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*_) ⇒ Object



114
115
116
# File 'lib/inspec/input.rb', line 114

def method_missing(*_)
  self
end

Instance Method Details

#is_a?(klass) ⇒ Boolean

Returns:

  • (Boolean)


126
127
128
129
130
131
132
133
# File 'lib/inspec/input.rb', line 126

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)


135
136
137
138
139
140
141
142
# File 'lib/inspec/input.rb', line 135

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)


118
119
120
# File 'lib/inspec/input.rb', line 118

def respond_to_missing?(_, _)
  true
end

#to_sObject



122
123
124
# File 'lib/inspec/input.rb', line 122

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