lib/pact_broker/domain/pacticipant.rb in pact_broker-2.79.1 vs lib/pact_broker/domain/pacticipant.rb in pact_broker-2.80.0

- old
+ new

@@ -1,18 +1,21 @@ -require 'pact_broker/db' -require 'pact_broker/messages' -require 'pact_broker/repositories/helpers' -require 'pact_broker/versions/latest_version' -require 'pact_broker/domain/label' +require "pact_broker/db" +require "pact_broker/messages" +require "pact_broker/repositories/helpers" +require "pact_broker/versions/latest_version" +require "pact_broker/domain/label" +require "pact_broker/string_refinements" +require "pact_broker/pacticipants/generate_display_name" module PactBroker module Domain class Pacticipant < Sequel::Model - include Messages - plugin :insert_ignore, identifying_columns: [:name] + include PactBroker::Pacticipants::GenerateDisplayName + using PactBroker::StringRefinements + plugin :insert_ignore, identifying_columns: [:name] plugin :timestamps, update_on_create: true set_primary_key :id one_to_many :versions, :order => :order, :reciprocal => :pacticipant @@ -40,38 +43,43 @@ PactBroker::Pacts::PactVersion.where(consumer: self).or(provider: self).delete PactBroker::Domain::Label.where(pacticipant: self).destroy super end + def before_save + super + self.display_name = generate_display_name(name) if display_name.blank? + self.main_branch = nil if main_branch.blank? + end + def latest_version versions.last end def to_s "Pacticipant: id=#{id}, name=#{name}" end - def validate - messages = [] - messages << message('errors.validation.attribute_missing', attribute: 'name') unless name - messages - end - def any_versions? PactBroker::Domain::Version.where(pacticipant: self).any? end end end end # Table: pacticipants # Columns: -# id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY -# name | text | -# repository_url | text | -# created_at | timestamp without time zone | NOT NULL -# updated_at | timestamp without time zone | NOT NULL +# id | integer | PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY +# name | text | +# repository_url | text | +# created_at | timestamp without time zone | NOT NULL +# updated_at | timestamp without time zone | NOT NULL +# display_name | text | +# repository_name | text | +# repository_namespace | text | +# main_development_branches | text | +# main_branch | text | # Indexes: # pacticipants_pkey | PRIMARY KEY btree (id) # pacticipants_name_key | UNIQUE btree (name) # ndx_ppt_name | btree (name) # Referenced By: @@ -91,5 +99,6 @@ # triggered_webhooks | triggered_webhooks_provider_id_fkey | (provider_id) REFERENCES pacticipants(id) # latest_pact_publication_ids_for_consumer_versions | latest_pact_publication_ids_for_consumer_versi_consumer_id_fkey | (consumer_id) REFERENCES pacticipants(id) ON DELETE CASCADE # latest_pact_publication_ids_for_consumer_versions | latest_pact_publication_ids_for_consumer_versi_provider_id_fkey | (provider_id) REFERENCES pacticipants(id) ON DELETE CASCADE # latest_verification_id_for_pact_version_and_provider_version | latest_v_id_for_pv_and_pv_consumer_id_fk | (consumer_id) REFERENCES pacticipants(id) ON DELETE CASCADE # latest_verification_id_for_pact_version_and_provider_version | latest_v_id_for_pv_and_pv_provider_id_fk | (provider_id) REFERENCES pacticipants(id) ON DELETE CASCADE +# currently_deployed_version_ids | currently_deployed_version_ids_pacticipant_id_fkey | (pacticipant_id) REFERENCES pacticipants(id) ON DELETE CASCADE