Class: ApiBomb::Commander
- Inherits:
-
Object
- Object
- ApiBomb::Commander
- Includes:
- Strategy::Naive
- Defined in:
- lib/api_bomb/commander.rb
Instance Attribute Summary collapse
-
#army ⇒ Object
readonly
Returns the value of attribute army.
-
#duration ⇒ Object
readonly
Returns the value of attribute duration.
-
#fronts ⇒ Object
readonly
Returns the value of attribute fronts.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
Instance Method Summary collapse
-
#initialize(army:, fronts: 1, duration: 10, logger: Logger.new(STDOUT), requests: nil) ⇒ Commander
constructor
A new instance of Commander.
- #start_attack! ⇒ Object
Methods included from Strategy::Naive
#attack, #attack_in_requests, #attack_in_time
Constructor Details
#initialize(army:, fronts: 1, duration: 10, logger: Logger.new(STDOUT), requests: nil) ⇒ Commander
Returns a new instance of Commander.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/api_bomb/commander.rb', line 6 def initialize(army:, fronts: 1, duration: 10, logger: Logger.new(STDOUT), requests: nil) @duration = duration @army = army @fighters = [] @statuses = [] @hold_times = [] @fronts = fronts @logger = logger @requests = requests end |
Instance Attribute Details
#army ⇒ Object (readonly)
Returns the value of attribute army.
4 5 6 |
# File 'lib/api_bomb/commander.rb', line 4 def army @army end |
#duration ⇒ Object (readonly)
Returns the value of attribute duration.
4 5 6 |
# File 'lib/api_bomb/commander.rb', line 4 def duration @duration end |
#fronts ⇒ Object (readonly)
Returns the value of attribute fronts.
4 5 6 |
# File 'lib/api_bomb/commander.rb', line 4 def fronts @fronts end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
4 5 6 |
# File 'lib/api_bomb/commander.rb', line 4 def logger @logger end |
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
4 5 6 |
# File 'lib/api_bomb/commander.rb', line 4 def requests @requests end |
Instance Method Details
#start_attack! ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/api_bomb/commander.rb', line 17 def start_attack! begin #I know that Timeout is really bad #but literarly there is no other generic way doing this #Fortunately we only do requests to an API so it shouldn't affect us logger.info "Starts firing requests" Timeout::timeout(duration) { attack } rescue Timeout::Error logger.info "Ceasefire!" end report_attack_result end |