Class: PactBroker::Pacts::PactPublication
- Inherits:
-
Object
- Object
- PactBroker::Pacts::PactPublication
- Extended by:
- Forwardable
- Defined in:
- lib/pact_broker/pacts/pact_publication.rb
Class Method Summary collapse
Instance Method Summary collapse
- #before_create ⇒ Object
- #consumer_version_tags ⇒ Object
- #head_pact_tags ⇒ Object
-
#head_tag_names ⇒ Object
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).
- #latest_for_branch? ⇒ Boolean
- #latest_verification ⇒ Object
- #to_domain ⇒ Object
- #to_domain_lightweight ⇒ Object
- #to_version_domain ⇒ Object
- #to_version_domain_lightweight ⇒ Object
Class Method Details
.subtract(a, b) ⇒ Object
42 43 44 45 |
# File 'lib/pact_broker/pacts/pact_publication.rb', line 42 def self.subtract(a, b) b_ids = b.collect(&:id) a.reject{ |pact_publication| b_ids.include?(pact_publication.id) } end |
Instance Method Details
#before_create ⇒ Object
47 48 49 50 |
# File 'lib/pact_broker/pacts/pact_publication.rb', line 47 def before_create super self.revision_number ||= 1 end |
#consumer_version_tags ⇒ Object
64 65 66 |
# File 'lib/pact_broker/pacts/pact_publication.rb', line 64 def consumer_version. end |
#head_pact_tags ⇒ Object
52 53 54 |
# File 'lib/pact_broker/pacts/pact_publication.rb', line 52 def consumer_version..select{ |tag| head_tag_names.include?(tag.name) } end |
#head_tag_names ⇒ Object
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)
58 59 60 61 62 |
# File 'lib/pact_broker/pacts/pact_publication.rb', line 58 def head_tag_names @head_tag_names ||= .select { |head_pact_publication| head_pact_publication.id == id } .collect { | head_pact_publication| head_pact_publication.values.fetch(:tag_name) } end |
#latest_for_branch? ⇒ Boolean
72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/pact_broker/pacts/pact_publication.rb', line 72 def latest_for_branch? return nil unless consumer_version.branch self_order = self.consumer_version.order versions_join = { Sequel[:pact_publications][:consumer_version_id] => Sequel[:cv][:id] } PactPublication.where(consumer_id: consumer_id, provider_id: provider_id) .join_consumer_versions(:cv, { Sequel[:cv][:branch] => consumer_version.branch} ) do Sequel[:cv][:order] > self_order end .empty? end |
#latest_verification ⇒ Object
68 69 70 |
# File 'lib/pact_broker/pacts/pact_publication.rb', line 68 def latest_verification pact_version.latest_verification end |
#to_domain ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/pact_broker/pacts/pact_publication.rb', line 85 def to_domain PactBroker::Domain::Pact.new( 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 ) end |
#to_domain_lightweight ⇒ Object
102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/pact_broker/pacts/pact_publication.rb', line 102 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_version_domain ⇒ Object
116 117 118 |
# File 'lib/pact_broker/pacts/pact_publication.rb', line 116 def to_version_domain OpenStruct.new(number: consumer_version.number, pacticipant: consumer, tags: consumer_version., order: consumer_version.order, branch: consumer_version.branch) end |
#to_version_domain_lightweight ⇒ Object
120 121 122 |
# File 'lib/pact_broker/pacts/pact_publication.rb', line 120 def to_version_domain_lightweight OpenStruct.new(number: consumer_version.number, pacticipant: consumer, order: consumer_version.order, branch: consumer_version.branch) end |