Class: HttpClientGenerator::Plugs::SetHeader
- Inherits:
-
Object
- Object
- HttpClientGenerator::Plugs::SetHeader
- Defined in:
- lib/http_client_generator/plugs/set_header.rb
Instance Method Summary collapse
- #call(req) ⇒ Object
-
#initialize(arg:, header:, func: nil) ⇒ SetHeader
constructor
A new instance of SetHeader.
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 |