Class: PactBroker::Repositories::WebhookRepository

Inherits:
Object
  • Object
show all
Includes:
PactBroker::Repositories
Defined in:
lib/pact_broker/repositories/webhook_repository.rb

Instance Method Summary collapse

Methods included from PactBroker::Repositories

#pact_repository, #pacticipant_repository, #tag_repository, #version_repository, #webhook_repository

Instance Method Details

#create(uuid, webhook, consumer, provider) ⇒ Object



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

def create uuid, webhook, consumer, provider
  db_webhook = Webhook.from_model webhook, consumer, provider
  db_webhook.uuid = uuid
  db_webhook.save
  webhook.request.headers.each_pair do | name, value |
    db_webhook.add_header WebhookHeader.from_model(name, value, db_webhook.id)
  end

  find_by_uuid db_webhook.uuid
end

#delete_by_pacticipant(pacticipant) ⇒ Object



37
38
39
40
# File 'lib/pact_broker/repositories/webhook_repository.rb', line 37

def delete_by_pacticipant pacticipant
  Webhook.where(consumer_id: pacticipant.id).destroy
  Webhook.where(provider_id: pacticipant.id).destroy
end

#delete_by_uuid(uuid) ⇒ Object



33
34
35
# File 'lib/pact_broker/repositories/webhook_repository.rb', line 33

def delete_by_uuid uuid
  Webhook.where(uuid: uuid).destroy
end

#find_allObject



42
43
44
# File 'lib/pact_broker/repositories/webhook_repository.rb', line 42

def find_all
  Webhook.all.collect { | db_webhook| db_webhook.to_model }
end

#find_by_consumer_and_provider(consumer, provider) ⇒ Object



46
47
48
# File 'lib/pact_broker/repositories/webhook_repository.rb', line 46

def find_by_consumer_and_provider consumer, provider
  Webhook.where(consumer_id: consumer.id, provider_id: provider.id).collect { | db_webhook| db_webhook.to_model }
end

#find_by_uuid(uuid) ⇒ Object



27
28
29
30
31
# File 'lib/pact_broker/repositories/webhook_repository.rb', line 27

def find_by_uuid uuid
  db_webhook = Webhook.where(uuid: uuid).single_record
  return nil if db_webhook.nil?
  db_webhook.to_model
end