Module: Arachni::Element::Capabilities::Inputtable

Included in:
Auditable
Defined in:
lib/arachni/element/capabilities/inputtable.rb

Overview

Author:

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#default_inputsHash (readonly)

Frozen version of #inputs, has all the original names and values.

Returns:



43
44
45
# File 'lib/arachni/element/capabilities/inputtable.rb', line 43

def default_inputs
  @default_inputs
end

#inputsHash

Note:

Can be modified via #update, #[]= or #inputs=.

Returns Frozen effective inputs.

Returns:

  • (Hash)

    Frozen effective inputs.



49
50
51
# File 'lib/arachni/element/capabilities/inputtable.rb', line 49

def inputs
  @inputs
end

Instance Method Details

#[](name) ⇒ String

Shorthand #inputs reader.

Parameters:

  • name (#to_s)

    Name.

Returns:



113
114
115
# File 'lib/arachni/element/capabilities/inputtable.rb', line 113

def []( name )
    @inputs[name.to_s]
end

#[]=(name, value) ⇒ Object

Shorthand #inputs writer.

Parameters:

  • name (#to_s)

    Name.

  • value (#to_s)

    Value.

Raises:



126
127
128
129
# File 'lib/arachni/element/capabilities/inputtable.rb', line 126

def []=( name, value )
    update( name.to_s => value.to_s )
    self[name]
end

#changesHash

Returns changes make to the #inputs‘s inputs.

Returns:

  • (Hash)

    Returns changes make to the #inputs‘s inputs.



91
92
93
94
95
96
97
98
# File 'lib/arachni/element/capabilities/inputtable.rb', line 91

def changes
    (@default_inputs.keys | @inputs.keys).inject( {} ) do |h, k|
        if @default_inputs[k] != @inputs[k]
            h[k] = @inputs[k]
        end
        h
    end
end

#dupObject



217
218
219
# File 'lib/arachni/element/capabilities/inputtable.rb', line 217

def dup
    copy_inputtable( super )
end

#has_inputs?(*args) ⇒ Bool

Checks whether or not the given inputs match the inputs ones.

Parameters:

  • args (Hash, Array, String, Symbol)

    Names of inputs to check (also accepts var-args).

Returns:

  • (Bool)


79
80
81
82
83
84
85
86
87
# File 'lib/arachni/element/capabilities/inputtable.rb', line 79

def has_inputs?( *args )
    if (h = args.first).is_a?( Hash )
        h.each { |k, v| return false if self[k] != v }
        true
    else
        keys = args.flatten.compact.map { |a| [a].map(&:to_s) }.flatten
        (@inputs.keys & keys).size == keys.size
    end
end

#inputtable_idString

Returns Uniquely identifies the #inputs.

Returns:



223
224
225
# File 'lib/arachni/element/capabilities/inputtable.rb', line 223

def inputtable_id
    inputs.sort_by { |k,_| k }.to_s
end

#resetObject

Resets the inputs to their original format/values.



101
102
103
104
105
# File 'lib/arachni/element/capabilities/inputtable.rb', line 101

def reset
    super if defined?( super )
    self.inputs = @default_inputs.dup
    self
end

#to_hObject



227
228
229
230
231
232
# File 'lib/arachni/element/capabilities/inputtable.rb', line 227

def to_h
    (defined?( super ) ? super : {}).merge(
        inputs:         inputs,
        default_inputs: default_inputs
    )
end

#try_input(&block) ⇒ Bool

Performs an input operation and silently handles Arachni::Element::Capabilities::Inputtable::Error::InvalidData.

Parameters:

  • block (Block)

    Input operation to try to perform.

Returns:

  • (Bool)

    ‘true` if the operation was successful, `false` otherwise.



206
207
208
209
210
211
212
213
214
215
# File 'lib/arachni/element/capabilities/inputtable.rb', line 206

def try_input( &block )
    block.call
    true
rescue Error::InvalidData => e
    return false if !respond_to?( :print_debug_level_1 )

    print_debug_level_1 e.to_s
    e.backtrace.each { |l| print_debug_level_1 l }
    false
end

#update(hash) ⇒ Auditable

Returns ‘self`.

Parameters:

  • hash (Hash)

    Inputs with which to update the #inputs inputs.

Returns:

Raises:



138
139
140
141
# File 'lib/arachni/element/capabilities/inputtable.rb', line 138

def update( hash )
    self.inputs = @inputs.merge( hash )
    self
end

#valid_input_data?(data) ⇒ Bool

This method is abstract.

Returns ‘true` if the data can be carried by the element’s inputs, ‘false` otherwise.

Parameters:

  • data (String)

    Data to check.

Returns:

  • (Bool)

    ‘true` if the data can be carried by the element’s inputs, ‘false` otherwise.



195
196
197
# File 'lib/arachni/element/capabilities/inputtable.rb', line 195

def valid_input_data?( data )
    true
end

#valid_input_name?(name) ⇒ Bool

This method is abstract.

Returns ‘true` if the name can be carried by the element’s inputs, ‘false` otherwise.

Parameters:

  • name (String)

    Name to check.

Returns:

  • (Bool)

    ‘true` if the name can be carried by the element’s inputs, ‘false` otherwise.



151
152
153
# File 'lib/arachni/element/capabilities/inputtable.rb', line 151

def valid_input_name?( name )
    true
end

#valid_input_name_data?(name) ⇒ Bool

Returns ‘true` if `name` is both a #valid_input_name? and contains #valid_input_data?.

Parameters:

  • name (String)

    Name to check.

Returns:



161
162
163
# File 'lib/arachni/element/capabilities/inputtable.rb', line 161

def valid_input_name_data?( name )
    valid_input_name?( name ) && valid_input_data?( name )
end

#valid_input_value?(value) ⇒ Bool

This method is abstract.

Returns ‘true` if the value can be carried by the element’s inputs, ‘false` otherwise.

Parameters:

  • value (String)

    Value to check.

Returns:

  • (Bool)

    ‘true` if the value can be carried by the element’s inputs, ‘false` otherwise.



173
174
175
# File 'lib/arachni/element/capabilities/inputtable.rb', line 173

def valid_input_value?( value )
    true
end

#valid_input_value_data?(value) ⇒ Bool

Returns ‘true` if `value` is both a #valid_input_value? and contains #valid_input_data?.

Parameters:

  • value (String)

    Value to check.

Returns:



183
184
185
# File 'lib/arachni/element/capabilities/inputtable.rb', line 183

def valid_input_value_data?( value )
    valid_input_value?( value ) && valid_input_data?( value )
end