class Arachni::Component::Options::Base
The base class for all options.
@author Tasos “Zapotek” Laskos <tasos.laskos@arachni-scanner.com> @abstract
Attributes
@return [Object] Default value.
@return [String] Description.
@return [Symbol] Name.
@return [Object] Assigned value.
Public Class Methods
@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
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
# File lib/arachni/component/options/base.rb, line 133 def ==( option ) hash == option.hash end
@return [Object]
{#value} or {#default}.
# File lib/arachni/component/options/base.rb, line 89 def effective_value @value || @default end
@return [Hash]
{#name} => {#normalize}
# File lib/arachni/component/options/base.rb, line 103 def for_component { name => normalize } end
# File lib/arachni/component/options/base.rb, line 137 def hash to_h.hash end
@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
@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
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
@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
@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
@return [Symbol]
Type identifying the option.
@abstract
# File lib/arachni/component/options/base.rb, line 97 def type :abstract end
@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