Class: PactBroker::Domain::Pacticipant

Inherits:
Sequel::Model
  • Object
show all
Includes:
Messages, Pacticipants::GenerateDisplayName
Defined in:
lib/pact_broker/domain/pacticipant.rb

Instance Method Summary collapse

Methods included from Pacticipants::GenerateDisplayName

call, #generate_display_name

Methods included from Messages

#message, #pluralize, #potential_duplicate_pacticipant_message, #validation_message

Instance Method Details

#any_versions?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/pact_broker/domain/pacticipant.rb', line 72

def any_versions?
  PactBroker::Domain::Version.where(pacticipant: self).any?
end

#before_destroyObject



49
50
51
52
53
54
55
56
# File 'lib/pact_broker/domain/pacticipant.rb', line 49

def before_destroy
  PactBroker::Pacts::PactPublication.where(provider: self).delete
  PactBroker::Domain::Verification.where(consumer: self).or(provider: self).delete
  PactBroker::Domain::Version.where(pacticipant: self).delete
  PactBroker::Pacts::PactVersion.where(consumer: self).or(provider: self).delete
  PactBroker::Domain::Label.where(pacticipant: self).destroy
  super
end

#before_saveObject



58
59
60
61
62
# File 'lib/pact_broker/domain/pacticipant.rb', line 58

def before_save
  super
  self.display_name = generate_display_name(name) if display_name.blank?
  self.main_branch = nil if main_branch.blank?
end

#branch_head_for(branch_name) ⇒ Object



76
77
78
# File 'lib/pact_broker/domain/pacticipant.rb', line 76

def branch_head_for(branch_name)
  branch_heads.find{ | branch_head | branch_head.branch_name == branch_name }
end

#label?(name) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/pact_broker/domain/pacticipant.rb', line 80

def label?(name)
  labels.any? { |label| label.name == name }
end

#latest_versionObject



64
65
66
# File 'lib/pact_broker/domain/pacticipant.rb', line 64

def latest_version
  versions.last
end

#to_sObject



68
69
70
# File 'lib/pact_broker/domain/pacticipant.rb', line 68

def to_s
  "Pacticipant: id=#{id}, name=#{name}"
end