Class: Arachni::OptionGroups::Input
- Inherits:
-
Arachni::OptionGroup
- Object
- Arachni::OptionGroup
- Arachni::OptionGroups::Input
- Defined in:
- lib/arachni/option_groups/input.rb
Overview
Holds options, and provides functionality, related to filling in inputs by name.
Constant Summary collapse
- DEFAULT_VALUES =
System default input values.
{ /name/i => 'arachni_name', /user/i => 'arachni_user', /usr/i => 'arachni_user', /pass/i => '5543!%arachni_secret', /txt/i => 'arachni_text', /num/i => '132', /amount/i => '100', /mail/i => '[email protected]', /account/i => '12', /id/i => '1', }
- DEFAULT =
'1'
Instance Attribute Summary collapse
-
#default_values ⇒ Hash<Regexp => String>
Default values for #values.
-
#force ⇒ Bool
Force #fill all inputs, not just the empty ones.
-
#values ⇒ Hash<Regexp => String, #call>
Patterns used to match input names and value to use to fill it in.
-
#without_defaults ⇒ Bool
‘true` if #default_values should be used, `false` otherwise.
Instance Method Summary collapse
-
#effective_values ⇒ Hash<Regexp => String>
#values, merged with #default_values if #without_defaults?.
-
#fill(parameters) ⇒ Hash
Tries to fill a hash with values of appropriate type based on the key of the parameter.
-
#force? ⇒ Bool
Force #fill all inputs, not just the empty ones.
- #format_values(values) ⇒ Object
- #to_h ⇒ Object
- #update_values_from_file(location) ⇒ Object
-
#value_for_name(name, use_default = true) ⇒ String?
Value for the ‘name` or `nil` if none could be found.
-
#without_defaults? ⇒ Bool
‘true` if #default_values should be used, `false` otherwise.
Methods inherited from Arachni::OptionGroup
#==, attr_accessor, #attributes, attributes, defaults, #defaults, #hash, inherited, #initialize, #merge, set_defaults, #to_hash, #to_rpc_data, #update, #validate
Constructor Details
This class inherits a constructor from Arachni::OptionGroup
Instance Attribute Details
#default_values ⇒ Hash<Regexp => String>
Returns Default values for #values.
42 43 44 |
# File 'lib/arachni/option_groups/input.rb', line 42 def default_values @default_values end |
#force ⇒ Bool
Returns Force #fill all inputs, not just the empty ones.
50 51 52 |
# File 'lib/arachni/option_groups/input.rb', line 50 def force @force end |
#values ⇒ Hash<Regexp => String, #call>
Returns Patterns used to match input names and value to use to fill it in. If the value is a callable object (like a ‘Proc`) its return value will be used instead – it will also be passed the name of the vector as an argument.
36 37 38 |
# File 'lib/arachni/option_groups/input.rb', line 36 def values @values end |
#without_defaults ⇒ Bool
Returns ‘true` if #default_values should be used, `false` otherwise.
46 47 48 |
# File 'lib/arachni/option_groups/input.rb', line 46 def without_defaults @without_defaults end |
Instance Method Details
#effective_values ⇒ Hash<Regexp => String>
Returns #values, merged with #default_values if #without_defaults?.
103 104 105 |
# File 'lib/arachni/option_groups/input.rb', line 103 def effective_values without_defaults? ? @values : default_values.merge( @values ) end |
#fill(parameters) ⇒ Hash
If #force? it will fill-in even non-empty inputs.
Tries to fill a hash with values of appropriate type based on the key of the parameter.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/arachni/option_groups/input.rb', line 68 def fill( parameters ) parameters = parameters.dup parameters.each do |k, v| next if !force? && !v.to_s.empty? value = value_for_name( k, false ) # Don't overwrite the default values of the parameters unless we've # fot a value, even if #force? is in effect. if parameters[k].to_s.empty? parameters[k] = value || DEFAULT elsif value parameters[k] = value end end parameters end |
#force? ⇒ Bool
Returns Force #fill all inputs, not just the empty ones.
121 122 123 |
# File 'lib/arachni/option_groups/input.rb', line 121 def force? !!@force end |
#format_values(values) ⇒ Object
136 137 138 139 140 141 142 143 144 |
# File 'lib/arachni/option_groups/input.rb', line 136 def format_values( values ) return if !values values.inject({}) do |h, (regexp, value)| regexp = regexp.is_a?( Regexp ) ? regexp : Regexp.new( regexp.to_s ) h.merge!( regexp => value ) h end end |
#to_h ⇒ Object
146 147 148 149 150 151 152 153 |
# File 'lib/arachni/option_groups/input.rb', line 146 def to_h h = super [:values, :default_values].each do |k| # We can't have blocks in there... h[k] = h[k].select{ |_, v| v.is_a? String }.my_stringify end h end |
#update_values_from_file(location) ⇒ Object
109 110 111 |
# File 'lib/arachni/option_groups/input.rb', line 109 def update_values_from_file( location ) @values.merge!( format_values( YAML.load_file( location ) ) ) end |
#value_for_name(name, use_default = true) ⇒ String?
Returns Value for the ‘name` or `nil` if none could be found.
93 94 95 96 97 98 99 |
# File 'lib/arachni/option_groups/input.rb', line 93 def value_for_name( name, use_default = true ) effective_values.each do |k, v| return v.respond_to?( :call ) ? v.call( name ).to_s : v if name =~ k end use_default ? DEFAULT : nil end |
#without_defaults? ⇒ Bool
Returns ‘true` if #default_values should be used, `false` otherwise.
115 116 117 |
# File 'lib/arachni/option_groups/input.rb', line 115 def without_defaults? !!@without_defaults end |