class Inferno::Repositories::Requests

Public Instance Methods

create(params) click to toggle source
# File lib/inferno/repositories/requests.rb, line 6
def create(params)
  request = self.class::Model.create(db_params(params))

  request_headers = (params[:request_headers] || []).map do |header|
    request.add_header(header.merge(request_id: request.index, type: 'request'))
  end
  response_headers = (params[:response_headers] || []).map do |header|
    request.add_header(header.merge(request_id: request.index, type: 'response'))
  end

  headers = (request_headers + response_headers).map { |header| headers_repo.build_entity(header.to_hash) }

  build_entity(
    request.to_hash
      .merge(headers: headers)
      .merge(non_db_params(params))
  )
end
find(id) click to toggle source
# File lib/inferno/repositories/requests.rb, line 25
def find(id)
  result =
    self.class::Model
      .where(id: id)
      .select(*entity_class::SUMMARY_FIELDS)
      .to_a
  return nil if result.blank?

  build_entity(result.first.to_hash)
end
find_full_request(id) click to toggle source
# File lib/inferno/repositories/requests.rb, line 36
def find_full_request(id)
  result =
    self.class::Model
      .find(id: id)
      .to_json_data(json_serializer_options)
      .deep_symbolize_keys!

  build_entity(result)
end
find_named_request(test_session_id, name) click to toggle source
# File lib/inferno/repositories/requests.rb, line 46
def find_named_request(test_session_id, name)
  results =
    self.class::Model
      .where(test_session_id: test_session_id, name: name.to_s)
      .map { |model| model.to_json_data(json_serializer_options) }
  return nil if results.blank?

  result = results.reduce { |max, current| current['index'] > max['index'] ? current : max }
  result.deep_symbolize_keys!

  build_entity(result)
end
json_serializer_options() click to toggle source
# File lib/inferno/repositories/requests.rb, line 69
def json_serializer_options
  {
    include: :headers
  }
end
requests_for_result(result_id) click to toggle source
# File lib/inferno/repositories/requests.rb, line 59
def requests_for_result(result_id)
  self.class::Model
    .order(:index)
    .where(result_id: result_id)
    .select(*entity_class::SUMMARY_FIELDS)
    .to_a
    .map(&:to_hash)
    .map! { |result| build_entity(result) }
end