Class: PactBroker::Labels::Repository

Inherits:
Object
  • Object
show all
Defined in:
lib/pact_broker/labels/repository.rb

Instance Method Summary collapse

Instance Method Details

#create(args) ⇒ Object



11
12
13
# File 'lib/pact_broker/labels/repository.rb', line 11

def create args
  Domain::Label.new(name: args.fetch(:name), pacticipant: args.fetch(:pacticipant)).save
end

#delete(args) ⇒ Object



24
25
26
# File 'lib/pact_broker/labels/repository.rb', line 24

def delete args
  find(args).delete
end

#delete_by_pacticipant_id(pacticipant_id) ⇒ Object



28
29
30
# File 'lib/pact_broker/labels/repository.rb', line 28

def delete_by_pacticipant_id pacticipant_id
  Sequel::Model.db[:labels].where(pacticipant_id: pacticipant_id).delete
end

#find(args) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/pact_broker/labels/repository.rb', line 15

def find args
  PactBroker::Domain::Label
    .select_all_qualified
    .join(:pacticipants, { id: :pacticipant_id })
    .where(Sequel.name_like(Sequel.qualify("labels", "name"), args.fetch(:label_name)))
    .where(Sequel.name_like(Sequel.qualify("pacticipants", "name"), args.fetch(:pacticipant_name)))
    .single_record
end

#get_all_unique_labels(pagination_options = {}) ⇒ Object



7
8
9
# File 'lib/pact_broker/labels/repository.rb', line 7

def get_all_unique_labels pagination_options = {}
  PactBroker::Domain::Label.distinct.select(:name).all_with_pagination_options(pagination_options)
end