Module: Arachni::Element::Capabilities::Inputtable
- Included in:
- Auditable, Arachni::Element::Cookie, Arachni::Element::Cookie::Capabilities::Inputtable, JSON, JSON::Capabilities::Inputtable, LinkTemplate, LinkTemplate::Capabilities::Inputtable, XML::Capabilities::Inputtable
- Defined in:
- lib/arachni/element/capabilities/inputtable.rb
Overview
Defined Under Namespace
Classes: Error
Constant Summary collapse
- INPUTTABLE_CACHE =
{ inputtable_id: Support::Cache::LeastRecentlyPushed.new( 1_000 ) }
Instance Attribute Summary collapse
-
#default_inputs ⇒ Hash
readonly
Frozen version of #inputs, has all the original names and values.
-
#inputs ⇒ Hash
Frozen effective inputs.
Instance Method Summary collapse
-
#[](name) ⇒ String
Shorthand #inputs reader.
-
#[]=(name, value) ⇒ Object
Shorthand #inputs writer.
-
#changes ⇒ Hash
Returns changes make to the #inputs‘s inputs.
- #dup ⇒ Object
-
#has_inputs?(*args) ⇒ Bool
Checks whether or not the given inputs match the inputs ones.
-
#inputtable_id ⇒ String
Uniquely identifies the #inputs.
-
#reset ⇒ Object
Resets the inputs to their original format/values.
- #to_h ⇒ Object
-
#try_input(&block) ⇒ Bool
Performs an input operation and silently handles Error::InvalidData.
-
#update(hash) ⇒ Auditable
‘self`.
-
#valid_input_data?(data) ⇒ Bool
abstract
‘true` if the data can be carried by the element’s inputs, ‘false` otherwise.
-
#valid_input_name?(name) ⇒ Bool
abstract
‘true` if the name can be carried by the element’s inputs, ‘false` otherwise.
-
#valid_input_name_data?(name) ⇒ Bool
‘true` if `name` is both a #valid_input_name? and contains #valid_input_data?.
-
#valid_input_value?(value) ⇒ Bool
abstract
‘true` if the value can be carried by the element’s inputs, ‘false` otherwise.
-
#valid_input_value_data?(value) ⇒ Bool
‘true` if `value` is both a #valid_input_value? and contains #valid_input_data?.
Instance Attribute Details
Instance Method Details
#[](name) ⇒ String
Shorthand #inputs reader.
117 118 119 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 117 def []( name ) @inputs[name.to_s] end |
#[]=(name, value) ⇒ Object
Shorthand #inputs writer.
130 131 132 133 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 130 def []=( name, value ) update( name.to_s => value.to_s ) self[name] end |
#changes ⇒ Hash
Returns changes make to the #inputs‘s inputs.
95 96 97 98 99 100 101 102 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 95 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 |
#dup ⇒ Object
223 224 225 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 223 def dup copy_inputtable( super ) end |
#has_inputs?(*args) ⇒ Bool
Checks whether or not the given inputs match the inputs ones.
83 84 85 86 87 88 89 90 91 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 83 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_id ⇒ String
Returns Uniquely identifies the #inputs.
229 230 231 232 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 229 def inputtable_id INPUTTABLE_CACHE[:inputtable_id][@inputs] ||= @inputs ? @inputs.sort_by { |k, _| k }.hash.to_s : '' end |
#reset ⇒ Object
Resets the inputs to their original format/values.
105 106 107 108 109 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 105 def reset super if defined?( super ) self.inputs = @default_inputs.deep_clone self end |
#to_h ⇒ Object
234 235 236 237 238 239 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 234 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.
212 213 214 215 216 217 218 219 220 221 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 212 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`.
142 143 144 145 146 147 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 142 def update( hash ) return self if hash.empty? self.inputs = @inputs.merge( hash ) self end |
#valid_input_data?(data) ⇒ Bool
Returns ‘true` if the data can be carried by the element’s inputs, ‘false` otherwise.
201 202 203 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 201 def valid_input_data?( data ) true end |
#valid_input_name?(name) ⇒ Bool
Returns ‘true` if the name can be carried by the element’s inputs, ‘false` otherwise.
157 158 159 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 157 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?.
167 168 169 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 167 def valid_input_name_data?( name ) valid_input_name?( name ) && valid_input_data?( name ) end |
#valid_input_value?(value) ⇒ Bool
Returns ‘true` if the value can be carried by the element’s inputs, ‘false` otherwise.
179 180 181 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 179 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?.
189 190 191 |
# File 'lib/arachni/element/capabilities/inputtable.rb', line 189 def valid_input_value_data?( value ) valid_input_value?( value ) && valid_input_data?( value ) end |