Class: Aranea::Faraday::FailureSimulator

Inherits:
Object
  • Object
show all
Defined in:
lib/aranea/faraday/aranea_middleware.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, config = {}) ⇒ FailureSimulator

Returns a new instance of FailureSimulator.



6
7
8
9
# File 'lib/aranea/faraday/aranea_middleware.rb', line 6

def initialize(app, config = {})
  @app = app
  @config = config
end

Instance Method Details

#call(request_env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/aranea/faraday/aranea_middleware.rb', line 11

def call(request_env)
  current_failure = Failure.current

  if current_failure.should_fail?(request_env, @app)
    # TODO: injectable logger
    puts "Aranea: simulating a failed call on #{request_env}"
    current_failure.respond!
  else
    @app.call(request_env)
  end
end