class Arachni::OptionGroup

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

Public Class Methods

attr_accessor( *vars ) click to toggle source
Calls superclass method
# File lib/arachni/option_group.rb, line 118
def self.attr_accessor( *vars )
    attributes.concat( vars )
    super( *vars )
end
attributes() click to toggle source
# File lib/arachni/option_group.rb, line 123
def self.attributes
    @attributes ||= []
end
defaults() click to toggle source

@return [Hash]

Specified default values for attribute readers.
# File lib/arachni/option_group.rb, line 22
def defaults
    @defaults ||= {}
end
inherited( child ) click to toggle source
# File lib/arachni/option_group.rb, line 45
def inherited( child )
    Options.register_group child
end
new() click to toggle source
# File lib/arachni/option_group.rb, line 50
def initialize
    defaults.each do |k, v|
        send "#{k}=", v
    end
end
set_defaults( default_values ) click to toggle source

Sets default values for attribute readers, when an attribute reader returns ‘nil` the default values will be returned instead.

@param [Hash] default_values

Default values for attributes.
# File lib/arachni/option_group.rb, line 31
def set_defaults( default_values )
    defaults.merge! default_values

    # Set the specified default values as overrides to the attribute
    # readers.
    defaults.each do |ivar, value|
        define_method "#{ivar}=" do |v|
            instance_variable_set( "@#{ivar}".to_sym, v.nil? ? value : v)
        end
    end

    defaults
end

Public Instance Methods

==( other ) click to toggle source
# File lib/arachni/option_group.rb, line 87
def ==( other )
    hash == other.hash
end
attributes() click to toggle source
# File lib/arachni/option_group.rb, line 127
def attributes
    self.class.attributes
end
defaults() click to toggle source

@return (see .defaults)

# File lib/arachni/option_group.rb, line 114
def defaults
    self.class.defaults
end
hash() click to toggle source
# File lib/arachni/option_group.rb, line 91
def hash
    to_h.hash
end
merge( other ) click to toggle source

@param [OptionGroup] other

@return [OptionGroup]

`self`
# File lib/arachni/option_group.rb, line 109
def merge( other )
    update( other.to_h )
end
to_h() click to toggle source

@return [Hash]

Values for all attribute accessors which aren't the defaults.
# File lib/arachni/option_group.rb, line 62
def to_h
    h = {}
    instance_variables.each do |ivar|
        method = normalize_ivar( ivar )
        sym    = method.to_sym
        value  = instance_variable_get( ivar )

        next if !respond_to?( "#{method}=" )

        h[sym] = value
    end
    h
end
to_hash() click to toggle source
# File lib/arachni/option_group.rb, line 75
def to_hash
    to_h
end
to_rpc_data() click to toggle source
# File lib/arachni/option_group.rb, line 56
def to_rpc_data
    to_h.my_stringify_keys(false)
end
update( options ) click to toggle source

@param [Hash] options

Data to use to update the group's attributes.

@return [OptionGroup]

`self`
# File lib/arachni/option_group.rb, line 100
def update( options )
    options.to_hash.each { |k, v| send( "#{k}=", v ) }
    self
end
validate() click to toggle source

@return [Hash]

Hash of errors with the name of the invalid options as the keys.

@abstract

# File lib/arachni/option_group.rb, line 83
def validate
    {}
end

Private Instance Methods

normalize_ivar( ivar ) click to toggle source
# File lib/arachni/option_group.rb, line 133
def normalize_ivar( ivar )
    ivar.to_s.gsub( '@', '' )
end