Sha256: 808b5b2d17ca0e235c5fd9511544168df7c87c5c227a9e8c2ed7ed90dea2b904

Contents?: true

Size: 1.89 KB

Versions: 3

Compression:

Stored size: 1.89 KB

Contents

module PactBroker
  module Matrix
    class QueryIds
      attr_reader :all_pacticipant_ids, :specified_pacticipant_ids, :pacticipant_ids, :pacticipant_version_ids

      # pacticipant_version_ids - the pacticipant version ids from the selectors where the pacticipant version id is the most specific criterion
      # pacticipant_ids - the pacticipant ids from the selectors where the pacticipant id is the most specific criterion
      # all_pacticipant_ids - the pacticipant ids from all the selectors, regardless of whether or not a pacticipant version has also been specified
      # specified_pacticipant_ids the IDs of the pacticipants that were specified in the can-i-deploy query
      def initialize(all_pacticipant_ids, specified_pacticipant_ids, pacticipant_ids, pacticipant_version_ids)
        @all_pacticipant_ids = all_pacticipant_ids
        @specified_pacticipant_ids = specified_pacticipant_ids
        @pacticipant_ids = pacticipant_ids
        @pacticipant_version_ids = pacticipant_version_ids
        @all_pacticipant_ids = all_pacticipant_ids
      end

      def self.from_selectors(selectors)
        most_specific_criteria = selectors.collect(&:most_specific_criterion)
        all_pacticipant_ids = selectors.collect(&:pacticipant_id).uniq
        specified_pacticipant_ids = selectors.select(&:specified?).collect(&:pacticipant_id).uniq
        pacticipant_version_ids = collect_ids(most_specific_criteria, :pacticipant_version_id).uniq
        pacticipant_ids = collect_ids(most_specific_criteria, :pacticipant_id).uniq
        QueryIds.new(all_pacticipant_ids, specified_pacticipant_ids, pacticipant_ids, pacticipant_version_ids)
      end

      def self.collect_ids(hashes, key)
        hashes.collect{ |s| s[key] }.flatten.compact
      end

      def pacticipant_id
        pacticipant_ids.first
      end

      def pacticipant_version_id
        pacticipant_version_ids.first
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
pact_broker-2.107.1 lib/pact_broker/matrix/query_ids.rb
pact_broker-2.107.0 lib/pact_broker/matrix/query_ids.rb
pact_broker-2.107.0.beta.1 lib/pact_broker/matrix/query_ids.rb