Class: Arachni::Component::Options::Base Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/arachni/component/options/base.rb

Overview

This class is abstract.

The base class for all options.

Author:

Direct Known Subclasses

Address, Bool, Float, Int, MultipleChoice, Object, Path, Port, String, URL

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ Base

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

Parameters:

  • name (Symbol)

    Name of the option.

  • options (Hash) (defaults to: {})

    Option attributes.

Options Hash (options):



44
45
46
47
48
49
50
51
52
53
54
55
# 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

Instance Attribute Details

#defaultObject (readonly)

Returns Default value.

Returns:



22
23
24
# File 'lib/arachni/component/options/base.rb', line 22

def default
  @default
end

#descriptionString (readonly)

Returns Description.

Returns:



19
20
21
# File 'lib/arachni/component/options/base.rb', line 19

def description
  @description
end

#nameSymbol (readonly)

Returns Name.

Returns:

  • (Symbol)

    Name.



16
17
18
# File 'lib/arachni/component/options/base.rb', line 16

def name
  @name
end

#valueObject

Returns Assigned value.

Returns:

  • (Object)

    Assigned value.



25
26
27
# File 'lib/arachni/component/options/base.rb', line 25

def value
  @value
end

Class Method Details

.from_rpc_data(data) ⇒ Base

Parameters:

Returns:



125
126
127
128
129
130
131
# 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

Instance Method Details

#==(option) ⇒ Object



133
134
135
# File 'lib/arachni/component/options/base.rb', line 133

def ==( option )
    hash == option.hash
end

#effective_valueObject

Returns #value or #default.

Returns:



89
90
91
# File 'lib/arachni/component/options/base.rb', line 89

def effective_value
    @value || @default
end

#for_componentHash

Returns #name => #normalize.

Returns:



103
104
105
# File 'lib/arachni/component/options/base.rb', line 103

def for_component
    { name => normalize }
end

#hashObject



137
138
139
# File 'lib/arachni/component/options/base.rb', line 137

def hash
    to_h.hash
end

#missing_value?Bool

Returns ‘true` if the option is #required? but has no #value, `false` otherwise.

Returns:



74
75
76
# File 'lib/arachni/component/options/base.rb', line 74

def missing_value?
    required? && effective_value.nil?
end

#normalizeObject

This method is abstract.

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

Returns:

  • (Object)

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



83
84
85
# File 'lib/arachni/component/options/base.rb', line 83

def normalize
    effective_value
end

#required?Bool

Returns true if this is a required option.

Returns:

  • (Bool)

    ‘true` if the option is required, `false` otherwise.



61
62
63
# File 'lib/arachni/component/options/base.rb', line 61

def required?
    @required
end

#to_hHash Also known as: to_hash

Returns:



108
109
110
111
112
113
114
# 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

#to_rpc_dataHash

Returns Data representing this instance that are suitable the RPC transmission.

Returns:

  • (Hash)

    Data representing this instance that are suitable the RPC transmission.



119
120
121
# 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

#typeSymbol

This method is abstract.

Returns Type identifying the option.

Returns:

  • (Symbol)

    Type identifying the option.



97
98
99
# File 'lib/arachni/component/options/base.rb', line 97

def type
    :abstract
end

#valid?Bool

Returns ‘true` if the option value is valid, `false` otherwise.

Returns:

  • (Bool)

    ‘true` if the option value is valid, `false` otherwise.



67
68
69
# File 'lib/arachni/component/options/base.rb', line 67

def valid?
    !missing_value?
end