Class: PactBroker::Domain::Webhook

Inherits:
Object
  • Object
show all
Includes:
Logging, Messages
Defined in:
lib/pact_broker/domain/webhook.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

included, #log_error

Methods included from Messages

#message, #potential_duplicate_pacticipant_message, #validation_message

Constructor Details

#initialize(attributes = {}) ⇒ Webhook

Returns a new instance of Webhook.



16
17
18
19
20
21
22
23
24
25
# File 'lib/pact_broker/domain/webhook.rb', line 16

def initialize attributes = {}
  @attributes = attributes
  @uuid = attributes[:uuid]
  @request = attributes[:request]
  @consumer = attributes[:consumer]
  @provider = attributes[:provider]
  @events = attributes[:events]
  @created_at = attributes[:created_at]
  @updated_at = attributes[:updated_at]
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



14
15
16
# File 'lib/pact_broker/domain/webhook.rb', line 14

def attributes
  @attributes
end

#consumerObject

Returns the value of attribute consumer.



13
14
15
# File 'lib/pact_broker/domain/webhook.rb', line 13

def consumer
  @consumer
end

#created_atObject

Returns the value of attribute created_at.



13
14
15
# File 'lib/pact_broker/domain/webhook.rb', line 13

def created_at
  @created_at
end

#eventsObject

Returns the value of attribute events.



13
14
15
# File 'lib/pact_broker/domain/webhook.rb', line 13

def events
  @events
end

#providerObject

Returns the value of attribute provider.



13
14
15
# File 'lib/pact_broker/domain/webhook.rb', line 13

def provider
  @provider
end

#requestObject

Returns the value of attribute request.



13
14
15
# File 'lib/pact_broker/domain/webhook.rb', line 13

def request
  @request
end

#updated_atObject

Returns the value of attribute updated_at.



13
14
15
# File 'lib/pact_broker/domain/webhook.rb', line 13

def updated_at
  @updated_at
end

#uuidObject

Returns the value of attribute uuid.



13
14
15
# File 'lib/pact_broker/domain/webhook.rb', line 13

def uuid
  @uuid
end

Instance Method Details

#consumer_nameObject



52
53
54
# File 'lib/pact_broker/domain/webhook.rb', line 52

def consumer_name
  consumer && consumer.name
end

#descriptionObject



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/pact_broker/domain/webhook.rb', line 27

def description
  if consumer && provider
    "A webhook for the pact between #{consumer.name} and #{provider.name}"
  elsif provider
    "A webhook for all pacts with provider #{provider.name}"
  elsif consumer
    "A webhook for all pacts with consumer #{consumer.name}"
  else
    "A webhook for all pacts"
  end
end

#execute(pact, verification, options) ⇒ Object



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

def execute pact, verification, options
  logger.info "Executing #{self}"
  request.build(pact: pact, verification: verification).execute(options)
end

#provider_nameObject



56
57
58
# File 'lib/pact_broker/domain/webhook.rb', line 56

def provider_name
  provider && provider.name
end

#request_descriptionObject



39
40
41
# File 'lib/pact_broker/domain/webhook.rb', line 39

def request_description
  request && request.description
end

#to_sObject



48
49
50
# File 'lib/pact_broker/domain/webhook.rb', line 48

def to_s
  "webhook for consumer=#{consumer_name} provider=#{provider_name} uuid=#{uuid}"
end

#trigger_on_contract_content_changed?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/pact_broker/domain/webhook.rb', line 60

def trigger_on_contract_content_changed?
  events.any?(&:contract_content_changed?)
end

#trigger_on_provider_verification_published?Boolean

Returns:

  • (Boolean)


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

def trigger_on_provider_verification_published?
  events.any?(&:provider_verification_published?)
end