Module: NxtHttpClient::Client::BatchPatch

Defined in:
lib/nxt_http_client/client/batch_patch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#callback_mapObject (readonly)

Returns the value of attribute callback_map.



4
5
6
# File 'lib/nxt_http_client/client/batch_patch.rb', line 4

def callback_map
  @callback_map
end

#ignore_around_callbacksObject (readonly)

Returns the value of attribute ignore_around_callbacks.



4
5
6
# File 'lib/nxt_http_client/client/batch_patch.rb', line 4

def ignore_around_callbacks
  @ignore_around_callbacks
end

Instance Method Details

#assign_batch_data(callback_map, ignore_around_callbacks) ⇒ Object



6
7
8
9
# File 'lib/nxt_http_client/client/batch_patch.rb', line 6

def assign_batch_data(callback_map, ignore_around_callbacks)
  @callback_map = callback_map
  @ignore_around_callbacks = ignore_around_callbacks
end

#finish(request, result, error, raise_errors: true) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/nxt_http_client/client/batch_patch.rb', line 41

def finish(request, result, error, raise_errors: true)
  result = run_after_fire_callbacks(request, request.response, result, error)

  case [error, raise_errors]
  in [nil, _]
    result
  in [_, true]
    raise error
  in [_, false]
    error
  end
end

#fire(url = '', **opts, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/nxt_http_client/client/batch_patch.rb', line 11

def fire(url = '', **opts, &block)
  response_handler = build_response_handler(opts[:response_handler], &block)
  request = build_request(url, **opts.except(:response_handler))
  callback_map[:request] = request

  setup_on_headers_callback(request, response_handler)
  setup_on_body_callback(request, response_handler)

  request.on_complete do |response|
    callback_map[:result] = callback_or_response(response, response_handler)
  rescue StandardError => e
    callback_map[:error] = e
  end

  if callbacks.any_around_callbacks? && ignore_around_callbacks != true
    raise(
      ArgumentError,
      <<~TXT
        `around_fire` callbacks are not supported when firing batches. \
        Pass `ignore_around_callbacks: true` to `execute_in_batch` \
        in order to acknowledge and muffle this.
      TXT
    )
  end

  run_before_fire_callbacks(request, response_handler)

  request
end