Class: PactBroker::Domain::IndexItem

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/domain/index_item.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(consumer, provider, latest_pact = nil, latest = true, latest_verification = nil, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = []) ⇒ IndexItem

rubocop:disable Metrics/ParameterLists



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pact_broker/domain/index_item.rb', line 22

def initialize(consumer, provider, latest_pact = nil, latest = true, latest_verification = nil, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [])
  @consumer = consumer
  @provider = provider
  @latest_pact = latest_pact
  @latest = latest
  @latest_verification = latest_verification
  @webhooks = webhooks
  @triggered_webhooks = triggered_webhooks
  @tags = tags
  @latest_verification_latest_tags = latest_verification_latest_tags
end

Instance Attribute Details

#consumerObject (readonly)

Returns the value of attribute consumer.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def consumer
  @consumer
end

#latest_pactObject (readonly)

Returns the value of attribute latest_pact.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def latest_pact
  @latest_pact
end

#latest_verificationObject (readonly)

Returns the value of attribute latest_verification.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def latest_verification
  @latest_verification
end

#latest_verification_latest_tagsObject (readonly)

Returns the value of attribute latest_verification_latest_tags.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def latest_verification_latest_tags
  @latest_verification_latest_tags
end

#providerObject (readonly)

Returns the value of attribute provider.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def provider
  @provider
end

#triggered_webhooksObject (readonly)

Returns the value of attribute triggered_webhooks.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def triggered_webhooks
  @triggered_webhooks
end

#webhooksObject (readonly)

Returns the value of attribute webhooks.



7
8
9
# File 'lib/pact_broker/domain/index_item.rb', line 7

def webhooks
  @webhooks
end

Class Method Details

.create(consumer, provider, latest_pact, latest, latest_verification, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = []) ⇒ Object

rubocop:disable Metrics/ParameterLists



16
17
18
# File 'lib/pact_broker/domain/index_item.rb', line 16

def self.create(consumer, provider, latest_pact, latest, latest_verification, webhooks = [], triggered_webhooks = [], tags = [], latest_verification_latest_tags = [])
  new(consumer, provider, latest_pact, latest, latest_verification, webhooks, triggered_webhooks, tags, latest_verification_latest_tags)
end

Instance Method Details

#<=>(other) ⇒ Object

Add logic for ignoring case



136
137
138
139
140
# File 'lib/pact_broker/domain/index_item.rb', line 136

def <=> other
  comp = consumer_name <=> other.consumer_name
  return comp unless comp == 0
  provider_name <=> other.provider_name
end

#==(other) ⇒ Object



43
44
45
# File 'lib/pact_broker/domain/index_item.rb', line 43

def == other
  eq?(other)
end

#any_webhooks?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/pact_broker/domain/index_item.rb', line 85

def any_webhooks?
  @webhooks.any?
end

#compare_name_asc(name1, name2) ⇒ Object



147
148
149
# File 'lib/pact_broker/domain/index_item.rb', line 147

def compare_name_asc name1, name2
  name1&.downcase <=> name2&.downcase
end

#compare_number_desc(number1, number2) ⇒ Object



151
152
153
154
155
156
157
158
159
# File 'lib/pact_broker/domain/index_item.rb', line 151

def compare_number_desc number1, number2
  if number1 && number2
    number2 <=> number1
  elsif number1
    1
  else
    -1
  end
end

#connected?(other) ⇒ Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/pact_broker/domain/index_item.rb', line 121

def connected? other
  include?(other.consumer) || include?(other.provider)
end

#consumer_nameObject



47
48
49
# File 'lib/pact_broker/domain/index_item.rb', line 47

def consumer_name
  consumer.name
end

#consumer_versionObject



67
68
69
# File 'lib/pact_broker/domain/index_item.rb', line 67

def consumer_version
  @latest_pact.consumer_version
end

#consumer_version_numberObject



59
60
61
# File 'lib/pact_broker/domain/index_item.rb', line 59

def consumer_version_number
  @latest_pact.consumer_version_number
end

#consumer_version_orderObject



63
64
65
# File 'lib/pact_broker/domain/index_item.rb', line 63

def consumer_version_order
  consumer_version.order
end

#eq?(other) ⇒ Boolean

rubocop:enable Metrics/ParameterLists

Returns:

  • (Boolean)


35
36
37
38
39
40
41
# File 'lib/pact_broker/domain/index_item.rb', line 35

def eq? other
  IndexItem === other && other.consumer == consumer && other.provider == provider &&
    other.latest_pact == latest_pact &&
    other.latest? == latest? &&
    other.latest_verification == latest_verification &&
    other.webhooks == webhooks
end

#ever_verified?Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/pact_broker/domain/index_item.rb', line 101

def ever_verified?
  !!latest_verification
end

#include?(pacticipant) ⇒ Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/pact_broker/domain/index_item.rb', line 125

def include? pacticipant
  pacticipant.id == consumer.id || pacticipant.id == provider.id
end

#last_activity_dateObject



169
170
171
# File 'lib/pact_broker/domain/index_item.rb', line 169

def last_activity_date
  @last_activity_date ||= [latest_pact.created_at, latest_verification ? latest_verification.execution_date : nil].compact.max
end

#last_webhook_execution_dateObject



93
94
95
# File 'lib/pact_broker/domain/index_item.rb', line 93

def last_webhook_execution_date
  @last_webhook_execution_date ||= @triggered_webhooks.any? ? @triggered_webhooks.sort{|a, b| a.created_at <=> b.created_at }.last.created_at : nil
end

#latest?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/pact_broker/domain/index_item.rb', line 55

def latest?
  @latest
end

#latest_verification_provider_version_numberObject



113
114
115
# File 'lib/pact_broker/domain/index_item.rb', line 113

def latest_verification_provider_version_number
  latest_verification.provider_version.number
end

#latest_verification_successful?Boolean

Returns:

  • (Boolean)


105
106
107
# File 'lib/pact_broker/domain/index_item.rb', line 105

def latest_verification_successful?
  latest_verification.success
end

#pact_changed_since_last_verification?Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/pact_broker/domain/index_item.rb', line 109

def pact_changed_since_last_verification?
  latest_verification.pact_version_sha != latest_pact.pact_version_sha
end

#pacticipantsObject



117
118
119
# File 'lib/pact_broker/domain/index_item.rb', line 117

def pacticipants
  [consumer, provider]
end

#provider_nameObject



51
52
53
# File 'lib/pact_broker/domain/index_item.rb', line 51

def provider_name
  provider.name
end

#provider_versionObject



71
72
73
# File 'lib/pact_broker/domain/index_item.rb', line 71

def provider_version
  @latest_verification ? @latest_verification.provider_version : nil
end

#provider_version_numberObject



75
76
77
# File 'lib/pact_broker/domain/index_item.rb', line 75

def provider_version_number
  @latest_verification ? @latest_verification.provider_version_number : nil
end

#pseudo_branch_verification_statusObject



97
98
99
# File 'lib/pact_broker/domain/index_item.rb', line 97

def pseudo_branch_verification_status
  @pseudo_branch_verification_status ||= PactBroker::Verifications::PseudoBranchStatus.new(@latest_pact, @latest_verification).to_sym
end

#tag_namesObject

these are the consumer tag names for which this pact publication is the latest with that tag



81
82
83
# File 'lib/pact_broker/domain/index_item.rb', line 81

def tag_names
  @tags
end

#to_aObject



165
166
167
# File 'lib/pact_broker/domain/index_item.rb', line 165

def to_a
  [consumer, provider]
end

#to_sObject



161
162
163
# File 'lib/pact_broker/domain/index_item.rb', line 161

def to_s
  "Pact between #{consumer_name} #{consumer_version_number} and #{provider_name} #{provider_version_number}"
end

#webhook_statusObject



89
90
91
# File 'lib/pact_broker/domain/index_item.rb', line 89

def webhook_status
  @webhook_status ||= PactBroker::Webhooks::Status.new(@latest_pact, @webhooks, @triggered_webhooks).to_sym
end