Class: Arachni::OptBase

Inherits:
Object show all
Defined in:
lib/arachni/component_options.rb

Overview

The base class for all options.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, attrs = []) ⇒ OptBase

Initializes a named option with the supplied attribute array. The array is composed of three values.

attrs = required (boolean type) attrs = description (string) attrs = default value attrs = possible enum values

Parameters:

  • name (String)

    the name of the options

  • attrs (Array) (defaults to: [])

    option attributes



74
75
76
77
78
79
80
# File 'lib/arachni/component_options.rb', line 74

def initialize( name, attrs = [] )
    @name     = name
    @required = attrs[0] || false
    @desc     = attrs[1]
    @default  = attrs[2]
    @enums    = [ *(attrs[3]) ].map { |x| x.to_s }
end

Instance Attribute Details

#defaultObject

The default value of the option.



44
45
46
# File 'lib/arachni/component_options.rb', line 44

def default
  @default
end

#descObject

The description of the option.



39
40
41
# File 'lib/arachni/component_options.rb', line 39

def desc
  @desc
end

#enumsObject

The list of potential valid values



59
60
61
# File 'lib/arachni/component_options.rb', line 59

def enums
  @enums
end

#nameObject

The name of the option.



29
30
31
# File 'lib/arachni/component_options.rb', line 29

def name
  @name
end

#ownerObject

The component that owns this option.



54
55
56
# File 'lib/arachni/component_options.rb', line 54

def owner
  @owner
end

#requiredObject

Whether or not the option is required.



34
35
36
# File 'lib/arachni/component_options.rb', line 34

def required
  @required
end

Instance Method Details

#empty_required_value?(value) ⇒ Boolean

Returns true if the value supplied is nil and it’s required to be a valid value

Returns:

  • (Boolean)


107
108
109
# File 'lib/arachni/component_options.rb', line 107

def empty_required_value?( value )
    return ( required? && value.nil? )
end

#normalize(value) ⇒ Object

Normalizes the supplied value to conform with the type that the option is conveying.



115
116
117
# File 'lib/arachni/component_options.rb', line 115

def normalize( value )
    value
end

#required?Boolean

Returns true if this is a required option.

Returns:

  • (Boolean)


85
86
87
# File 'lib/arachni/component_options.rb', line 85

def required?
    return required
end

#to_hHash

Converts the Options object to hash

Returns:

  • (Hash)


124
125
126
127
128
129
130
131
# File 'lib/arachni/component_options.rb', line 124

def to_h
    hash = Hash.new
    self.instance_variables.each {
        |var|
        hash[var.to_s.gsub( /@/, '' )] = self.instance_variable_get( var )
    }
    return hash.merge( 'type' => type )
end

#type?(in_type) ⇒ Boolean

Returns true if the supplied type is equivalent to this option’s type.

Returns:

  • (Boolean)


92
93
94
# File 'lib/arachni/component_options.rb', line 92

def type?( in_type )
    return (type == in_type)
end

#valid?(value) ⇒ Boolean

If it’s required and the value is nil or empty, then it’s not valid.

Returns:

  • (Boolean)


99
100
101
# File 'lib/arachni/component_options.rb', line 99

def valid?( value )
    return ( required? && ( value == nil || value.to_s.empty? ) ) ? false : true
end