Class: MockDnsServer::ConditionalAction
- Inherits:
-
Object
- Object
- MockDnsServer::ConditionalAction
- Defined in:
- lib/mock_dns_server/conditional_action.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
Returns the value of attribute action.
-
#condition ⇒ Object
Returns the value of attribute condition.
-
#description ⇒ Object
Returns the value of attribute description.
-
#max_uses ⇒ Object
Returns the value of attribute max_uses.
-
#use_count ⇒ Object
Returns the value of attribute use_count.
Instance Method Summary collapse
- #eligible_to_run? ⇒ Boolean
- #increment_use_count ⇒ Object
-
#initialize(condition, action, max_uses) ⇒ Object
constructor
The value returned by the action, e.g.
- #run(request, sender, context, protocol) ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(condition, action, max_uses) ⇒ Object
Returns the value returned by the action, e.g. the message, or array of messages, it sent.
15 16 17 18 19 20 |
# File 'lib/mock_dns_server/conditional_action.rb', line 15 def initialize(condition, action, max_uses) @condition = condition @action = action @max_uses = max_uses @use_count = 0 end |
Instance Attribute Details
#action ⇒ Object
Returns the value of attribute action.
5 6 7 |
# File 'lib/mock_dns_server/conditional_action.rb', line 5 def action @action end |
#condition ⇒ Object
Returns the value of attribute condition.
5 6 7 |
# File 'lib/mock_dns_server/conditional_action.rb', line 5 def condition @condition end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/mock_dns_server/conditional_action.rb', line 5 def description @description end |
#max_uses ⇒ Object
Returns the value of attribute max_uses.
5 6 7 |
# File 'lib/mock_dns_server/conditional_action.rb', line 5 def max_uses @max_uses end |
#use_count ⇒ Object
Returns the value of attribute use_count.
5 6 7 |
# File 'lib/mock_dns_server/conditional_action.rb', line 5 def use_count @use_count end |
Instance Method Details
#eligible_to_run? ⇒ Boolean
31 32 33 34 |
# File 'lib/mock_dns_server/conditional_action.rb', line 31 def eligible_to_run? max_not_reached = max_uses.nil? || use_count < max_uses max_not_reached && condition.call end |
#increment_use_count ⇒ Object
23 24 25 |
# File 'lib/mock_dns_server/conditional_action.rb', line 23 def increment_use_count @use_count += 1 end |
#run(request, sender, context, protocol) ⇒ Object
36 37 38 39 |
# File 'lib/mock_dns_server/conditional_action.rb', line 36 def run(request, sender, context, protocol) # TODO: Output to history? action.call(request, sender, context, protocol) end |
#to_s ⇒ Object
27 28 29 |
# File 'lib/mock_dns_server/conditional_action.rb', line 27 def to_s "#{super.to_s}; condition: #{condition.to_s}, action = #{action.to_s}, max_uses = #{max_uses}" end |