Sha256: 48f79e28885d9f35ff56b305d8cbce99513eab62efe6d3f77b6315d832bbd52b

Contents?: true

Size: 1.85 KB

Versions: 4

Compression:

Stored size: 1.85 KB

Contents

require 'pact_broker/repositories'
require 'pact_broker/logging'
require 'pact_broker/domain/index_item'
require 'pact_broker/matrix/head_row'
require 'pact_broker/matrix/aggregated_row'

module PactBroker

  module Index
    class Service

      extend PactBroker::Repositories
      extend PactBroker::Services
      extend PactBroker::Logging

      def self.find_index_items options = {}
        rows = PactBroker::Matrix::HeadRow
          .select_all_qualified
          .eager(:latest_triggered_webhooks)
          .eager(:webhooks)

        rows = rows.consumer(options[:consumer_name]) if options[:consumer_name]
        rows = rows.provider(options[:provider_name]) if options[:provider_name]

        if !options[:tags]
          rows = rows.where(consumer_version_tag_name: nil)
        else
          if options[:tags].is_a?(Array)
            rows = rows.where(consumer_version_tag_name: options[:tags]).or(consumer_version_tag_name: nil)
          end
          rows = rows.eager(:consumer_version_tags)
                .eager(:provider_version_tags)
                .eager(:latest_verification_for_consumer_version_tag)
                .eager(:latest_verification_for_consumer_and_provider)
        end
        rows = rows.all.group_by(&:pact_publication_id).values.collect{ | rows| Matrix::AggregatedRow.new(rows) }

        rows.sort.collect do | row |
          # TODO simplify. Do we really need 3 layers of abstraction?
          PactBroker::Domain::IndexItem.create(
            row.consumer,
            row.provider,
            row.pact,
            row.overall_latest?,
            row.latest_verification,
            row.webhooks,
            row.latest_triggered_webhooks,
            options[:tags] ? row.consumer_head_tag_names : [],
            options[:tags] ? row.provider_version_tags.select(&:latest?) : []
          )
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
pact_broker-2.35.0 lib/pact_broker/index/service.rb
pact_broker-2.34.0 lib/pact_broker/index/service.rb
pact_broker-2.33.0 lib/pact_broker/index/service.rb
pact_broker-2.32.0 lib/pact_broker/index/service.rb