Module: Inferno::DSL::RequestStorage
- Defined in:
- lib/inferno/dsl/request_storage.rb
Overview
This module handles storing and retrieving requests/responses made by FHIR/HTTP clients
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #load_named_requests ⇒ Object
-
#load_tagged_requests(*tags) ⇒ Inferno::Entities::Request
Returns requests which match all of the given tags.
- #named_request(name) ⇒ Object
-
#request ⇒ Inferno::Entities::Request?
Returns the most recent FHIR/HTTP request.
-
#requests ⇒ Array<Inferno::Entities::Request>
Returns the FHIR/HTTP requests that have been made in this ‘Test`.
-
#resource ⇒ FHIR::Model?
Returns the FHIR resource from the response to the most recent FHIR request.
-
#response ⇒ Hash?
Returns the response from the most recent FHIR/HTTP request.
- #store_request(direction, name: nil, tags: [], &block) ⇒ Object
Class Method Details
.included(klass) ⇒ Object
6 7 8 |
# File 'lib/inferno/dsl/request_storage.rb', line 6 def self.included(klass) klass.extend ClassMethods end |
Instance Method Details
#load_named_requests ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/inferno/dsl/request_storage.rb', line 77 def load_named_requests requests_repo = Inferno::Repositories::Requests.new self.class.named_requests_used.map do |request_name| request_alias = self.class.config.request_name(request_name) request = requests_repo.find_named_request(test_session_id, request_alias) if request.nil? raise Exceptions::SkipException, "Request `#{request_alias}` was not made in a previous test as expected." end requests << request end end |
#load_tagged_requests(*tags) ⇒ Inferno::Entities::Request
Returns requests which match all of the given tags
43 44 45 46 47 48 49 |
# File 'lib/inferno/dsl/request_storage.rb', line 43 def load_tagged_requests(*) return [] if .blank? Repositories::Requests.new.tagged_requests(test_session_id, ).tap do |tagged_requests| requests.concat(tagged_requests) end end |
#named_request(name) ⇒ Object
52 53 54 |
# File 'lib/inferno/dsl/request_storage.rb', line 52 def named_request(name) requests.find { |request| request.name == self.class.config.request_name(name.to_sym) } end |
#request ⇒ Inferno::Entities::Request?
Returns the most recent FHIR/HTTP request
20 21 22 |
# File 'lib/inferno/dsl/request_storage.rb', line 20 def request requests.last end |
#requests ⇒ Array<Inferno::Entities::Request>
Returns the FHIR/HTTP requests that have been made in this ‘Test`
13 14 15 |
# File 'lib/inferno/dsl/request_storage.rb', line 13 def requests @requests ||= [] end |
#resource ⇒ FHIR::Model?
Returns the FHIR resource from the response to the most recent FHIR request
35 36 37 |
# File 'lib/inferno/dsl/request_storage.rb', line 35 def resource request&.resource end |
#response ⇒ Hash?
Returns the response from the most recent FHIR/HTTP request
27 28 29 |
# File 'lib/inferno/dsl/request_storage.rb', line 27 def response request&.response end |
#store_request(direction, name: nil, tags: [], &block) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/inferno/dsl/request_storage.rb', line 57 def store_request(direction, name: nil, tags: [], &block) response = block.call name = self.class.config.request_name(name) request = if response.is_a? FHIR::ClientReply Entities::Request.from_fhir_client_reply( response, direction:, name:, test_session_id:, tags: ) else Entities::Request.from_http_response( response, direction:, name:, test_session_id:, tags: ) end requests << request request end |