Class: PactBroker::UI::ViewDomain::IndexItem

Inherits:
Object
  • Object
show all
Includes:
Api::PactBrokerUrls
Defined in:
lib/pact_broker/ui/view_models/index_item.rb

Instance Method Summary collapse

Methods included from Api::PactBrokerUrls

#badge_url_for_latest_pact, #consumer_webhooks_url, #hal_browser_url, #label_url, #labels_url, #latest_pacts_url, #latest_untagged_pact_url, #latest_verifications_for_consumer_version_url, #latest_version_url, #matrix_url_from_params, #new_verification_url, #pact_triggered_webhooks_url, #pact_url_from_params, #pact_version_url, #pact_versions_url, #pacticipant_url, #pacticipant_url_from_params, #pacticipants_url, #previous_distinct_diff_url, #previous_distinct_pact_version_url, #provider_webhooks_url, #tag_url, #tags_url, #templated_diff_url, #templated_label_url_for_pacticipant, #templated_tag_url_for_pacticipant, #triggered_webhook_logs_url, #url_encode, #verification_publication_url, #verification_triggered_webhooks_url, #verification_url, #verification_url_from_params, #version_url, #version_url_from_params, #versions_url, #webhook_execution_url, #webhooks_for_consumer_and_provider_url, #webhooks_for_pact_url, #webhooks_status_url, #webhooks_url

Constructor Details

#initialize(relationship) ⇒ IndexItem

Returns a new instance of IndexItem.



13
14
15
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 13

def initialize relationship
  @relationship = relationship
end

Instance Method Details

#<=>(other) ⇒ Object



147
148
149
150
151
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 147

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

#any_webhooks?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 65

def any_webhooks?
  @relationship.any_webhooks?
end

#consumer_group_urlObject



45
46
47
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 45

def consumer_group_url
  Helpers::URLHelper.group_url consumer_name
end

#consumer_nameObject



17
18
19
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 17

def consumer_name
  @relationship.consumer_name
end

#consumer_version_latest_tag_namesObject



37
38
39
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 37

def consumer_version_latest_tag_names
  @relationship.tag_names
end

#consumer_version_numberObject



25
26
27
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 25

def consumer_version_number
  PactBroker::Versions::AbbreviateNumber.call(@relationship.consumer_version_number)
end

#last_verified_dateObject



107
108
109
110
111
112
113
114
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 107

def last_verified_date
  if @relationship.ever_verified?
    date = @relationship.latest_verification.execution_date
    PactBroker::DateHelper.distance_of_time_in_words(date, DateTime.now) + " ago"
  else
    ""
  end
end

#latest?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 33

def latest?
  @relationship.latest?
end

#latest_pact_urlObject



53
54
55
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 53

def latest_pact_url
  "#{pactigration_base_url('', @relationship)}/latest"
end

#pact_matrix_urlObject



61
62
63
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 61

def pact_matrix_url
  Helpers::URLHelper.matrix_url consumer_name, provider_name
end

#pact_urlObject



57
58
59
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 57

def pact_url
  PactBroker::Api::PactBrokerUrls.pact_url('', @relationship)
end

#provider_group_urlObject



49
50
51
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 49

def provider_group_url
  Helpers::URLHelper.group_url provider_name
end

#provider_nameObject



21
22
23
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 21

def provider_name
  @relationship.provider_name
end

#provider_version_latest_tag_namesObject



41
42
43
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 41

def provider_version_latest_tag_names
  @relationship.latest_verification_latest_tags.collect(&:name)
end

#provider_version_numberObject



29
30
31
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 29

def provider_version_number
  PactBroker::Versions::AbbreviateNumber.call(@relationship.provider_version_number)
end

#publication_date_of_latest_pactObject



116
117
118
119
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 116

def publication_date_of_latest_pact
  date = @relationship.latest_pact.created_at
  PactBroker::DateHelper.distance_of_time_in_words(date, DateTime.now) + " ago"
end

#short_version_number(version_number) ⇒ Object



153
154
155
156
157
158
159
160
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 153

def short_version_number version_number
  return "" if version_number.nil?
  if version_number.size > 12
    version_number[0..12] + "..."
  else
    version_number
  end
end

#show_webhook_status?Boolean

Returns:

  • (Boolean)


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

def show_webhook_status?
  @relationship.latest?
end

#verification_statusObject



121
122
123
124
125
126
127
128
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 121

def verification_status
  case @relationship.verification_status
    when :success then "success"
    when :stale then "warning"
    when :failed then "danger"
    else ""
  end
end

#verification_tooltipObject



134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 134

def verification_tooltip
  case @relationship.verification_status
  when :success
    "Successfully verified by #{provider_name} (v#{short_version_number(@relationship.latest_verification_provider_version_number)})"
  when :stale
    "Pact has changed since last successful verification by #{provider_name} (v#{short_version_number(@relationship.latest_verification_provider_version_number)})"
  when :failed
    "Verification by #{provider_name} (v#{short_version_number(@relationship.latest_verification_provider_version_number)}) failed"
  else
    nil
  end
end

#warning?Boolean

Returns:

  • (Boolean)


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

def warning?
  verification_status == 'warning'
end

#webhook_labelObject



69
70
71
72
73
74
75
76
77
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 69

def webhook_label
  return "" unless show_webhook_status?
  case @relationship.webhook_status
    when :none then "Create"
    when :success, :failure then webhook_last_execution_date
    when :retrying then "Retrying"
    when :not_run then "Not run"
  end
end

#webhook_last_execution_dateObject



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

def webhook_last_execution_date
  PactBroker::DateHelper.distance_of_time_in_words(@relationship.last_webhook_execution_date, DateTime.now) + " ago"
end

#webhook_statusObject



79
80
81
82
83
84
85
86
87
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 79

def webhook_status
  return "" unless show_webhook_status?
  case @relationship.webhook_status
    when :success then "success"
    when :failure then "danger"
    when :retrying then "warning"
    else ""
  end
end

#webhook_urlObject



97
98
99
100
101
102
103
104
105
# File 'lib/pact_broker/ui/view_models/index_item.rb', line 97

def webhook_url
  url = case @relationship.webhook_status
    when :none
      PactBroker::Api::PactBrokerUrls.webhooks_for_consumer_and_provider_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider
    else
      PactBroker::Api::PactBrokerUrls.webhooks_status_url @relationship.latest_pact.consumer, @relationship.latest_pact.provider
  end
  "/hal-browser/browser.html##{url}"
end