Class: Linzer::Message
- Inherits:
-
Object
- Object
- Linzer::Message
- Defined in:
- lib/linzer/message.rb
Constant Summary collapse
- DERIVED_COMPONENT =
{ method: :request_method, authority: :authority, path: :path_info, status: :status, "target-uri": :url, scheme: :scheme, "request-target": :fullpath, query: :query_string }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #[](field_name) ⇒ Object
- #attached_request? ⇒ Boolean
- #field?(f) ⇒ Boolean
- #headers ⇒ Object
-
#initialize(operation, attached_request: nil) ⇒ Message
constructor
A new instance of Message.
- #request? ⇒ Boolean
- #response? ⇒ Boolean
Constructor Details
#initialize(operation, attached_request: nil) ⇒ Message
Returns a new instance of Message.
5 6 7 8 9 10 |
# File 'lib/linzer/message.rb', line 5 def initialize(operation, attached_request: nil) @operation = operation validate @attached_request = attached_request ? Message.new(attached_request) : nil freeze end |
Class Method Details
.parse_structured_dictionary(str, field_name = nil) ⇒ Object
57 58 59 60 61 |
# File 'lib/linzer/message.rb', line 57 def parse_structured_dictionary(str, field_name = nil) Starry.parse_dictionary(str) rescue Starry::ParseError => _ raise Error.new "Cannot parse \"#{field_name}\" field. Bailing out!" end |
Instance Method Details
#[](field_name) ⇒ Object
45 46 47 48 49 50 51 52 53 54 |
# File 'lib/linzer/message.rb', line 45 def [](field_name) name = parse_field_name(field_name) return nil if name.nil? if field_name.start_with?("@") retrieve(name, :derived) else retrieve(name, :field) end end |
#attached_request? ⇒ Boolean
20 21 22 |
# File 'lib/linzer/message.rb', line 20 def attached_request? !!@attached_request end |
#field?(f) ⇒ Boolean
30 31 32 |
# File 'lib/linzer/message.rb', line 30 def field?(f) !!self[f] end |
#headers ⇒ Object
24 25 26 27 28 |
# File 'lib/linzer/message.rb', line 24 def headers return @operation.headers if response? || @operation.respond_to?(:headers) Request.headers(@operation) end |
#request? ⇒ Boolean
12 13 14 |
# File 'lib/linzer/message.rb', line 12 def request? @operation.is_a?(Rack::Request) || @operation.respond_to?(:request_method) end |
#response? ⇒ Boolean
16 17 18 |
# File 'lib/linzer/message.rb', line 16 def response? @operation.is_a?(Rack::Response) || @operation.respond_to?(:status) end |