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

Returns a new instance of IndexItem.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/pact_broker/domain/index_item.rb', line 10

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.



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

def consumer
  @consumer
end

#latest_pactObject (readonly)

Returns the value of attribute latest_pact.



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

def latest_pact
  @latest_pact
end

#latest_verificationObject (readonly)

Returns the value of attribute latest_verification.



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

def latest_verification
  @latest_verification
end

#latest_verification_latest_tagsObject (readonly)

Returns the value of attribute latest_verification_latest_tags.



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

def latest_verification_latest_tags
  @latest_verification_latest_tags
end

#providerObject (readonly)

Returns the value of attribute provider.



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

def provider
  @provider
end

#triggered_webhooksObject (readonly)

Returns the value of attribute triggered_webhooks.



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

def triggered_webhooks
  @triggered_webhooks
end

#webhooksObject (readonly)

Returns the value of attribute webhooks.



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

def webhooks
  @webhooks
end

Class Method Details

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



22
23
24
# File 'lib/pact_broker/domain/index_item.rb', line 22

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



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

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

#==(other) ⇒ Object



34
35
36
# File 'lib/pact_broker/domain/index_item.rb', line 34

def == other
  eq?(other)
end

#any_webhooks?Boolean

Returns:

  • (Boolean)


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

def any_webhooks?
  @webhooks.any?
end

#connected?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#consumer_nameObject



38
39
40
# File 'lib/pact_broker/domain/index_item.rb', line 38

def consumer_name
  consumer.name
end

#consumer_versionObject



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

def consumer_version
  @latest_pact.consumer_version
end

#consumer_version_numberObject



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

def consumer_version_number
  @latest_pact.consumer_version_number
end

#eq?(other) ⇒ Boolean

Returns:

  • (Boolean)


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

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)


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

def ever_verified?
  !!latest_verification
end

#include?(pacticipant) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#last_activity_dateObject



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

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



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

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)


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

def latest?
  @latest
end

#latest_verification_provider_version_numberObject



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

def latest_verification_provider_version_number
  latest_verification.provider_version.number
end

#latest_verification_successful?Boolean

Returns:

  • (Boolean)


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

def latest_verification_successful?
  latest_verification.success
end

#pact_changed_since_last_verification?Boolean

Returns:

  • (Boolean)


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

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

#pacticipantsObject



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

def pacticipants
  [consumer, provider]
end

#provider_nameObject



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

def provider_name
  provider.name
end

#provider_versionObject



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

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

#provider_version_numberObject



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

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

#pseudo_branch_verification_statusObject



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

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



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

def tag_names
  @tags
end

#to_aObject



134
135
136
# File 'lib/pact_broker/domain/index_item.rb', line 134

def to_a
  [consumer, provider]
end

#to_sObject



130
131
132
# File 'lib/pact_broker/domain/index_item.rb', line 130

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

#webhook_statusObject



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

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