Sha256: 122df68a80994dc100c96db0ff747e6c7771fdfebf4fbb96ed9a6f769991c0dc

Contents?: true

Size: 1.69 KB

Versions: 12

Compression:

Stored size: 1.69 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)

        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

12 entries across 12 versions & 1 rubygems

Version Path
pact_broker-2.31.0 lib/pact_broker/index/service.rb
pact_broker-2.30.0 lib/pact_broker/index/service.rb
pact_broker-2.29.0 lib/pact_broker/index/service.rb
pact_broker-2.27.6 lib/pact_broker/index/service.rb
pact_broker-2.27.5 lib/pact_broker/index/service.rb
pact_broker-2.27.4 lib/pact_broker/index/service.rb
pact_broker-2.27.3 lib/pact_broker/index/service.rb
pact_broker-2.27.2 lib/pact_broker/index/service.rb
pact_broker-2.27.0 lib/pact_broker/index/service.rb
pact_broker-2.26.1 lib/pact_broker/index/service.rb
pact_broker-2.26.0 lib/pact_broker/index/service.rb
pact_broker-2.25.0 lib/pact_broker/index/service.rb