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:, header:, func: nil) ⇒ SetHeader

Returns a new instance of SetHeader.



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

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

Instance Method Details

#call(req) ⇒ Object



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

def call(req)
  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