Class: IesAuth::Rest::Headers
- Inherits:
-
Object
- Object
- IesAuth::Rest::Headers
- Extended by:
- Forwardable
- Defined in:
- lib/ies_auth/rest/headers.rb
Overview
A header builder class for outgoing requests
Instance Method Summary collapse
-
#+(other) ⇒ Headers
Add the values of one ‘Headers` into another.
-
#assign_each_to(obj) ⇒ Object
Assign each header to object via :[].
-
#build(args = {}) ⇒ Headers
Add or update the request headers.
-
#each_pair ⇒ Object
Forwards to :@heads.
-
#fetch ⇒ Object
Forwards to :@heads.
-
#initialize(args = {}) ⇒ Headers
constructor
A new instance of Headers.
-
#remove(key) ⇒ String, ...
Remove key/value from headers via key.
-
#to_h ⇒ Hash
Hash of the ‘Headers`.
Constructor Details
#initialize(args = {}) ⇒ Headers
Returns a new instance of Headers.
20 21 22 |
# File 'lib/ies_auth/rest/headers.rb', line 20 def initialize(args = {}) build(args) end |
Instance Method Details
#+(other) ⇒ Headers
Add the values of one ‘Headers` into another
58 59 60 61 62 63 64 65 |
# File 'lib/ies_auth/rest/headers.rb', line 58 def +(other) raise TypeError, "Headers type expected, #{other.class} given" \ unless other.is_a? Headers @heads.merge(other.instance_variable_get(:@heads)) self end |
#assign_each_to(obj) ⇒ Object
Assign each header to object via :[]
38 39 40 41 42 43 44 |
# File 'lib/ies_auth/rest/headers.rb', line 38 def assign_each_to(obj) each_pair do |header, value| obj[header] = value end obj end |
#build(args = {}) ⇒ Headers
Add or update the request headers
27 28 29 30 31 32 33 34 35 |
# File 'lib/ies_auth/rest/headers.rb', line 27 def build(args = {}) @heads ||= {} args.to_h.each do |(key, value)| @heads[key] = value end self end |
#each_pair ⇒ Object
Forwards to :@heads.
18 |
# File 'lib/ies_auth/rest/headers.rb', line 18 def_delegators :@heads, :each_pair, :fetch |
#fetch ⇒ Object
Forwards to :@heads.
18 |
# File 'lib/ies_auth/rest/headers.rb', line 18 def_delegators :@heads, :each_pair, :fetch |
#remove(key) ⇒ String, ...
Remove key/value from headers via key
50 51 52 |
# File 'lib/ies_auth/rest/headers.rb', line 50 def remove(key) @heads.delete(key) end |
#to_h ⇒ Hash
Returns hash of the ‘Headers`.
68 69 70 |
# File 'lib/ies_auth/rest/headers.rb', line 68 def to_h @heads end |