Class: Msf::OptEnum

Inherits:
OptBase show all
Defined in:
lib/msf/core/opt_enum.rb

Overview

Enum option.

Instance Attribute Summary collapse

Attributes inherited from OptBase

#advanced, #aliases, #conditions, #default, #enums, #evasion, #fallbacks, #max_length, #name, #owner, #regex, #required

Instance Method Summary collapse

Methods inherited from OptBase

#advanced?, #display_value, #empty_required_value?, #evasion?, #invalid_value_length?, #required?, #type?, #validate_on_assignment?

Constructor Details

#initialize(in_name, attrs = [], required: true, **kwargs) ⇒ OptEnum

This overrides required default from ‘false’ to ‘true’



15
16
17
18
# File 'lib/msf/core/opt_enum.rb', line 15

def initialize(in_name, attrs = [],
               required: true, **kwargs)
  super
end

Instance Attribute Details

#desc_stringObject (protected)

:nodoc:



47
48
49
# File 'lib/msf/core/opt_enum.rb', line 47

def desc_string
  @desc_string
end

Instance Method Details

#descObject



40
41
42
43
# File 'lib/msf/core/opt_enum.rb', line 40

def desc
  str = enums.join(', ') if enums
  "#{desc_string || ''} (Accepted: #{str})"
end

#desc=(value) ⇒ Object



35
36
37
38
# File 'lib/msf/core/opt_enum.rb', line 35

def desc=(value)
  self.desc_string = value
  desc
end

#normalize(value = self.value) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/msf/core/opt_enum.rb', line 27

def normalize(value = self.value)
  if valid?(value)
    value.to_s
  else
    nil
  end
end

#typeObject



10
11
12
# File 'lib/msf/core/opt_enum.rb', line 10

def type
  return 'enum'
end

#valid?(value = self.value, check_empty: true) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
23
24
25
# File 'lib/msf/core/opt_enum.rb', line 20

def valid?(value = self.value, check_empty: true)
  return false if check_empty && empty_required_value?(value)
  return true if value.nil? && !required?

  !value.nil? && enums.include?(value.to_s)
end