class Arachni::Component::Options::Base

The base class for all options.

@author Tasos “Zapotek” Laskos <tasos.laskos@arachni-scanner.com> @abstract

Attributes

default[R]

@return [Object] Default value.

description[R]

@return [String] Description.

name[R]

@return [Symbol] Name.

value[RW]

@return [Object] Assigned value.

Public Class Methods

from_rpc_data( data ) click to toggle source

@param [Hash] data {#to_rpc_data} @return [Base]

# File lib/arachni/component/options/base.rb, line 125
def self.from_rpc_data( data )
    data.delete('type')
    data.delete('class')
    name = data.delete('name')

    new name, data.my_symbolize_keys(false)
end
new( name, options = {} ) click to toggle source

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

@param [Symbol] name

Name of the option.

@param [Hash] options

Option attributes.

@option options [String, Symbol] :name

{#name Name} for this option.

@option options [String] :description

{#name Description} for this option.

@option options [Bool] :required (false)

Is this option {#required?}.

@option options [Object] :default

{#name Default value} for this option.

@option options [Object] :value

{#value Value} for this option.
# File lib/arachni/component/options/base.rb, line 44
def initialize( name, options = {} )
    options = options.dup

    @name        = name.to_sym
    @required    = !!options.delete(:required)
    @description = options.delete(:description)
    @default     = options.delete(:default)
    @value       = options.delete(:value)

    return if options.empty?
    fail ArgumentError, "Unknown options: #{options.keys.join( ', ' )}"
end

Public Instance Methods

==( option ) click to toggle source
# File lib/arachni/component/options/base.rb, line 133
def ==( option )
    hash == option.hash
end
effective_value() click to toggle source

@return [Object]

{#value} or {#default}.
# File lib/arachni/component/options/base.rb, line 89
def effective_value
    @value || @default
end
for_component() click to toggle source

@return [Hash]

{#name} => {#normalize}
# File lib/arachni/component/options/base.rb, line 103
def for_component
    { name => normalize }
end
hash() click to toggle source
# File lib/arachni/component/options/base.rb, line 137
def hash
    to_h.hash
end
missing_value?() click to toggle source

@return [Bool]

`true` if the option is {#required?} but has no {#value},
`false` otherwise.
# File lib/arachni/component/options/base.rb, line 74
def missing_value?
    required? && effective_value.nil?
end
normalize() click to toggle source

@return [Object]

Convert the user-provided {#value} (which will usually be a
user-supplied String) to the desired Ruby type.

@abstract

# File lib/arachni/component/options/base.rb, line 83
def normalize
    effective_value
end
required?() click to toggle source

Returns true if this is a required option.

@return [Bool]

`true` if the option is required, `false` otherwise.
# File lib/arachni/component/options/base.rb, line 61
def required?
    @required
end
to_h() click to toggle source

@return [Hash]

# File lib/arachni/component/options/base.rb, line 108
def to_h
    hash = {}
    instance_variables.each do |var|
        hash[var.to_s.gsub( /@/, '' ).to_sym] = instance_variable_get( var )
    end
    hash.merge( type: type )
end
Also aliased as: to_hash
to_hash()
Alias for: to_h
to_rpc_data() click to toggle source

@return [Hash]

Data representing this instance that are suitable the RPC transmission.
# File lib/arachni/component/options/base.rb, line 119
def to_rpc_data
    to_h.merge( class: self.class.to_s ).my_stringify_keys
end
type() click to toggle source

@return [Symbol]

Type identifying the option.

@abstract

# File lib/arachni/component/options/base.rb, line 97
def type
    :abstract
end
valid?() click to toggle source

@return [Bool]

`true` if the option value is valid, `false` otherwise.
# File lib/arachni/component/options/base.rb, line 67
def valid?
    !missing_value?
end