Class: Arachni::OptionGroup

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

Overview

Author:

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeOptionGroup

Returns a new instance of OptionGroup.



50
51
52
53
54
# File 'lib/arachni/option_group.rb', line 50

def initialize
    defaults.each do |k, v|
        send "#{k}=", v
    end
end

Class Method Details

.attr_accessor(*vars) ⇒ Object



118
119
120
121
# File 'lib/arachni/option_group.rb', line 118

def self.attr_accessor( *vars )
    attributes.concat( vars )
    super( *vars )
end

.attributesObject



123
124
125
# File 'lib/arachni/option_group.rb', line 123

def self.attributes
    @attributes ||= []
end

.defaultsHash

Returns Specified default values for attribute readers.

Returns:

  • (Hash)

    Specified default values for attribute readers.



22
23
24
# File 'lib/arachni/option_group.rb', line 22

def defaults
    @defaults ||= {}
end

.set_defaults(default_values) ⇒ Object

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

Parameters:

  • default_values (Hash)

    Default values for attributes.



31
32
33
34
35
36
37
38
39
40
41
42
43
# 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

Instance Method Details

#==(other) ⇒ Object



87
88
89
# File 'lib/arachni/option_group.rb', line 87

def ==( other )
    hash == other.hash
end

#attributesObject



127
128
129
# File 'lib/arachni/option_group.rb', line 127

def attributes
    self.class.attributes
end

#defaultsHash

Returns Specified default values for attribute readers.

Returns:

  • (Hash)

    Specified default values for attribute readers.



114
115
116
# File 'lib/arachni/option_group.rb', line 114

def defaults
    self.class.defaults
end

#hashObject



91
92
93
# File 'lib/arachni/option_group.rb', line 91

def hash
    to_h.hash
end

#merge(other) ⇒ OptionGroup

Returns self.

Parameters:

Returns:



109
110
111
# File 'lib/arachni/option_group.rb', line 109

def merge( other )
    update( other.to_h )
end

#to_hHash

Returns Values for all attribute accessors which aren't the defaults.

Returns:

  • (Hash)

    Values for all attribute accessors which aren't the defaults.



62
63
64
65
66
67
68
69
70
71
72
73
74
# 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_hashObject



75
76
77
# File 'lib/arachni/option_group.rb', line 75

def to_hash
    to_h
end

#to_rpc_dataObject



56
57
58
# File 'lib/arachni/option_group.rb', line 56

def to_rpc_data
    to_h.my_stringify_keys(false)
end

#update(options) ⇒ OptionGroup

Returns self.

Parameters:

  • options (Hash)

    Data to use to update the group's attributes.

Returns:



100
101
102
103
# File 'lib/arachni/option_group.rb', line 100

def update( options )
    options.to_hash.each { |k, v| send( "#{k}=", v ) }
    self
end

#validateHash

This method is abstract.

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

Returns:

  • (Hash)

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



83
84
85
# File 'lib/arachni/option_group.rb', line 83

def validate
    {}
end