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
- #field?(f) ⇒ Boolean
- #headers ⇒ Object
-
#initialize(operation) ⇒ Message
constructor
A new instance of Message.
- #request? ⇒ Boolean
- #response? ⇒ Boolean
Constructor Details
#initialize(operation) ⇒ Message
Returns a new instance of Message.
5 6 7 8 |
# File 'lib/linzer/message.rb', line 5 def initialize(operation) @operation = operation freeze end |
Class Method Details
.parse_structured_dictionary(str, field_name = nil) ⇒ Object
58 59 60 61 62 |
# File 'lib/linzer/message.rb', line 58 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
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/linzer/message.rb', line 39 def [](field_name) if !field_name.start_with?("@") return @operation.env[Request.rack_header_name(field_name)] if request? return @operation.headers[field_name] # if response? end method = DERIVED_COMPONENT[field_name] case field_name when "@query" return "?#{@operation.public_send(method)}" when /\A(?<field>(?<prefix>@query-param)(?<rest>;name=.+)\Z)/ return parse_query_param Regexp.last_match end method ? @operation.public_send(method) : nil end |
#field?(f) ⇒ Boolean
24 25 26 |
# File 'lib/linzer/message.rb', line 24 def field?(f) !!self[f] end |
#headers ⇒ Object
18 19 20 21 22 |
# File 'lib/linzer/message.rb', line 18 def headers return @operation.headers if response? || @operation.respond_to?(:headers) Request.headers(@operation) end |
#request? ⇒ Boolean
10 11 12 |
# File 'lib/linzer/message.rb', line 10 def request? @operation.is_a?(Rack::Request) || @operation.respond_to?(:request_method) end |
#response? ⇒ Boolean
14 15 16 |
# File 'lib/linzer/message.rb', line 14 def response? @operation.is_a?(Rack::Response) || @operation.respond_to?(:status) end |