Class: PactBroker::Labels::Repository

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

Instance Method Summary collapse

Methods included from Repositories::Helpers

#all_allowing_lazy_load, #all_forbidding_lazy_load, #mysql?, #name_like, #no_columns_selected?, #order_append_ignore_case, #order_ignore_case, #pacticipant_id_for_name, #postgres?, #select_all_qualified, #select_append_all_qualified, #select_for_subquery

Instance Method Details

#create(args) ⇒ Object



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

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

#delete(args) ⇒ Object



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

def delete args
  find(args).delete
end

#delete_by_pacticipant_id(pacticipant_id) ⇒ Object



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

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

#find(args) ⇒ Object



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

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