Class: Ruckus::Mutator::Modifier
Overview
The guts; each Modifier class implements some way of screwing with a value to catch bugs. Modifiers are all created with keyword args; the base class catches:
- now
-
true/false (def: false) fire immediately, just once, irrespective of probability, even if probability is provided.
- prob
-
(def: 100) pctg chance this modifier will fire on this tick
- max_steps
-
number of times to fire this modifier before it stops and just starts acting like a no-op. -1 equals no max
Direct Known Subclasses
Adder, FormatStrings, Hibit, Metacharacters, Multiplier, PathTraversal, Random, Randomizer, Reset, SQLStrings, XSS
Instance Method Summary collapse
-
#<<(x) ⇒ Object
This is what callers call.
-
#go? ⇒ Boolean
Should this fire, based on prob?.
-
#initialize(opts = {}) ⇒ Modifier
constructor
A new instance of Modifier.
-
#mod(x) ⇒ Object
Base class stub does nothing.
Constructor Details
#initialize(opts = {}) ⇒ Modifier
Returns a new instance of Modifier.
68 69 70 71 72 73 74 |
# File 'lib/ruckus/mutator.rb', line 68 def initialize(opts={}) @now = opts[:now] || false @prob = opts[:prob] || 100 @max_steps = opts[:max_steps] || 700 @cur = 0 @opts = opts end |
Instance Method Details
#<<(x) ⇒ Object
This is what callers call. Subclasses do not override this method. This implements probability and max-steps. How it looks:
str = modifier << str
98 99 100 101 102 |
# File 'lib/ruckus/mutator.rb', line 98 def <<(x) return x if (@cur += 1) > @max_steps && @max_steps != -1 return x if not go? mod(x) end |
#go? ⇒ Boolean
Should this fire, based on prob?
78 79 80 81 82 83 84 |
# File 'lib/ruckus/mutator.rb', line 78 def go? if @now @now = false return true end rand(100) < @prob end |
#mod(x) ⇒ Object
Base class stub does nothing. Subclasses override this method to implement logic. Callers don’t use this method, though: they use operator<<.
90 |
# File 'lib/ruckus/mutator.rb', line 90 def mod(x); x; end |