Class: HttpClientGenerator::Plugs::SetHeader

Inherits:
Object
  • Object
show all
Defined in:
lib/http_client_generator/plugs/set_header.rb

Instance Method Summary collapse

Constructor Details

#initialize(arg: nil, value: nil, header:, func: nil) ⇒ SetHeader

Returns a new instance of SetHeader.



8
9
10
11
12
13
# File 'lib/http_client_generator/plugs/set_header.rb', line 8

def initialize(arg: nil, value: nil, header:, func: nil)
  @arg = arg
  @header = header
  @func = func
  @value = value
end

Instance Method Details

#call(req) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/http_client_generator/plugs/set_header.rb', line 15

def call(req)
  return process_header_value(req) if @value

  arg = req.rest_args[@arg]

  req.headers[@header] =
    case @func&.arity
    in 1
      @func.(arg)
    in 2
      @func.(req, arg)
    in nil
      arg
    end

  req
end