class PactBroker::Pacts::PactPublication

Public Class Methods

subtract(a, *b) click to toggle source
# File lib/pact_broker/pacts/pact_publication.rb, line 71
def self.subtract(a, *b)
  b_ids = b.flat_map{ |pact_publications| pact_publications.collect(&:id) }
  a.reject{ |pact_publication| b_ids.include?(pact_publication.id) }
end

Public Instance Methods

<=>(other) click to toggle source
# File lib/pact_broker/pacts/pact_publication.rb, line 198
def <=> other
  self_fields = [consumer.name.downcase, provider.name.downcase, consumer_version_order || 0]
  other_fields = [other.consumer.name.downcase, other.provider.name.downcase, other.consumer_version_order || 0]
  self_fields <=> other_fields
end
before_create() click to toggle source
Calls superclass method
# File lib/pact_broker/pacts/pact_publication.rb, line 76
def before_create
  super
  self.revision_number ||= 1
end
consumer_version_tags() click to toggle source

If the consumer_version is already loaded, and it already has tags, use those otherwise, load them directly.

# File lib/pact_broker/pacts/pact_publication.rb, line 95
def consumer_version_tags
  if associations[:consumer_version] && associations[:consumer_version].associations[:tags]
    consumer_version.tags
  else
    tags
  end
end
eager_for_domain_with_content() click to toggle source
# File lib/pact_broker/pacts/pact_publication.rb, line 60
def eager_for_domain_with_content
  eager(:tags, :consumer, :provider, :pact_version, { consumer_version: :branch_versions })
end
head_pact_tags() click to toggle source
# File lib/pact_broker/pacts/pact_publication.rb, line 81
def head_pact_tags
  consumer_version.tags.select{ |tag| head_tag_names.include?(tag.name) }
end
head_tag_names() click to toggle source

The names of the tags for which this pact is the latest pact with that tag (ie. it is not necessarily the pact for the latest consumer version with the given tag)

# File lib/pact_broker/pacts/pact_publication.rb, line 87
def head_tag_names
  @head_tag_names ||= head_pact_publications_for_tags
    .select { |head_pact_publication| head_pact_publication.id == id }
    .collect { | head_pact_publication| head_pact_publication.values.fetch(:tag_name) }
end
latest_for_branch?() click to toggle source
# File lib/pact_broker/pacts/pact_publication.rb, line 111
def latest_for_branch?
  if !defined?(@latest_for_branch)
    if consumer_version.branch_versions.empty?
      @latest_for_branch = nil
    else
      self_order = self.consumer_version.order
      @latest_for_branch = consumer_version.branch_versions.any? do | branch_version |
        branch_versions_join = {
          Sequel[:cv][:id] => Sequel[:branch_versions][:version_id],
          Sequel[:branch_versions][:branch_name] => branch_version.branch_name
        }
        PactPublication.where(consumer_id: consumer_id, provider_id: provider_id)
          .join_consumer_versions(:cv) do
            Sequel[:cv][:order] > self_order
          end
          .join(:branch_versions, branch_versions_join)
        .empty?
      end
    end
  end
  @latest_for_branch
end
latest_main_branch_verification() click to toggle source
# File lib/pact_broker/pacts/pact_publication.rb, line 107
def latest_main_branch_verification
  pact_version.latest_main_branch_verification
end
latest_verification() click to toggle source
# File lib/pact_broker/pacts/pact_publication.rb, line 103
def latest_verification
  pact_version.latest_verification
end
pact_version_sha() click to toggle source
# File lib/pact_broker/pacts/pact_publication.rb, line 194
def pact_version_sha
  pact_version.sha
end
to_domain() click to toggle source

rubocop:disable Metrics/CyclomaticComplexity

# File lib/pact_broker/pacts/pact_publication.rb, line 135
def to_domain
  attributes = {
    id: id,
    provider: provider,
    consumer: consumer,
    consumer_version_number: consumer_version.number,
    consumer_version: to_version_domain,
    revision_number: revision_number,
    json_content: pact_version.content,
    pact_version_sha: pact_version.sha,
    latest_verification: pact_version.latest_verification,
    created_at: created_at,
    head_tag_names: [],
    db_model: self
  }

  if associations[:tags] || consumer_version.associations[:tags]
    attributes[:consumer_version_tag_names] = associations[:tags]&.collect(&:name) || consumer_version.associations[:tags]&.collect(&:name)
  end

  if consumer_version.associations[:branch_versions]
    attributes[:consumer_version_branch_names] = consumer_version.branch_versions.collect(&:branch_name)
  end

  PactBroker::Domain::Pact.new(attributes)
end
to_domain_lightweight() click to toggle source

rubocop:enable Metrics/CyclomaticComplexity

# File lib/pact_broker/pacts/pact_publication.rb, line 163
def to_domain_lightweight
  PactBroker::Domain::Pact.new(
    id: id,
    provider: provider,
    consumer: consumer,
    consumer_version_number: consumer_version.number,
    consumer_version: to_version_domain_lightweight,
    revision_number: revision_number,
    pact_version_sha: pact_version.sha,
    created_at: created_at,
    db_model: self
    )
end
to_domain_with_content() click to toggle source
# File lib/pact_broker/pacts/pact_publication.rb, line 186
def to_domain_with_content
  to_domain
end
to_head_pact() click to toggle source
# File lib/pact_broker/pacts/pact_publication.rb, line 190
def to_head_pact
  HeadPact.new(to_domain, consumer_version.number, values[:tag_name])
end
to_version_domain() click to toggle source

Think we really could just use the version here.

# File lib/pact_broker/pacts/pact_publication.rb, line 178
def to_version_domain
  consumer_version
end
to_version_domain_lightweight() click to toggle source
# File lib/pact_broker/pacts/pact_publication.rb, line 182
def to_version_domain_lightweight
  consumer_version
end
with_version_branches_and_tags() click to toggle source
# File lib/pact_broker/pacts/pact_publication.rb, line 65
def with_version_branches_and_tags
  consumer_version.tags
  consumer_version.branch_versions
  self
end

Private Instance Methods

cached_domain_for_delegation() click to toggle source
# File lib/pact_broker/pacts/pact_publication.rb, line 206
def cached_domain_for_delegation
  @domain_object ||= to_domain
end