Class: HttpMonkey::Configuration::Behaviours
- Inherits:
-
Object
- Object
- HttpMonkey::Configuration::Behaviours
- Defined in:
- lib/http_monkey/configuration/behaviours.rb
Instance Attribute Summary collapse
-
#unknown_behaviour ⇒ Object
readonly
Returns the value of attribute unknown_behaviour.
Instance Method Summary collapse
- #clear! ⇒ Object
- #find(code) ⇒ Object
-
#initialize ⇒ Behaviours
constructor
A new instance of Behaviours.
- #initialize_copy(source) ⇒ Object
- #on(code, &block) ⇒ Object
- #on_unknown(&block) ⇒ Object
Constructor Details
#initialize ⇒ Behaviours
Returns a new instance of Behaviours.
7 8 9 |
# File 'lib/http_monkey/configuration/behaviours.rb', line 7 def initialize self.clear! end |
Instance Attribute Details
#unknown_behaviour ⇒ Object (readonly)
Returns the value of attribute unknown_behaviour.
5 6 7 |
# File 'lib/http_monkey/configuration/behaviours.rb', line 5 def unknown_behaviour @unknown_behaviour end |
Instance Method Details
#clear! ⇒ Object
17 18 19 20 21 22 |
# File 'lib/http_monkey/configuration/behaviours.rb', line 17 def clear! @behaviours = {} @behaviours_range = {} @unknown_behaviour = nil nil end |
#find(code) ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/http_monkey/configuration/behaviours.rb', line 37 def find(code) behaviour = @behaviours[code] if behaviour.nil? _, behaviour = @behaviours_range.detect do |range, proc| range.include?(code) end end behaviour end |
#initialize_copy(source) ⇒ Object
11 12 13 14 15 |
# File 'lib/http_monkey/configuration/behaviours.rb', line 11 def initialize_copy(source) super @behaviours = @behaviours.clone @behaviours_range = @behaviours_range.clone end |
#on(code, &block) ⇒ Object
24 25 26 27 28 29 30 31 |
# File 'lib/http_monkey/configuration/behaviours.rb', line 24 def on(code, &block) if code.is_a?(Integer) @behaviours[code] = block elsif code.respond_to?(:include?) @behaviours_range[code] = block end nil end |
#on_unknown(&block) ⇒ Object
33 34 35 |
# File 'lib/http_monkey/configuration/behaviours.rb', line 33 def on_unknown(&block) @unknown_behaviour = block end |