Class: PactBroker::Pacticipants::Repository

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

Instance Method Summary collapse

Methods included from Repositories::Helpers

#case_sensitivity_options, #mysql?, #name_like, #order_ignore_case, #select_all_qualified, #select_for_subquery

Instance Method Details

#create(args) ⇒ Object



44
45
46
# File 'lib/pact_broker/pacticipants/repository.rb', line 44

def create args
  PactBroker::Domain::Pacticipant.new(name: args[:name], repository_url: args[:repository_url]).save(raise_on_save_failure: true)
end

#find(options = {}) ⇒ Object



23
24
25
26
27
# File 'lib/pact_broker/pacticipants/repository.rb', line 23

def find options = {}
  query = PactBroker::Domain::Pacticipant.select_all_qualified
  query = query.label(options[:label_name]) if options[:label_name]
  query.order_ignore_case(Sequel[:pacticipants][:name]).all
end

#find_allObject



19
20
21
# File 'lib/pact_broker/pacticipants/repository.rb', line 19

def find_all
  find
end

#find_all_pacticipant_versions_in_reverse_order(name) ⇒ Object



29
30
31
32
33
34
# File 'lib/pact_broker/pacticipants/repository.rb', line 29

def find_all_pacticipant_versions_in_reverse_order name
  PactBroker::Domain::Version.select_all_qualified
    .join(:pacticipants, {id: :pacticipant_id})
    .where(name_like(:name, name))
    .reverse_order(:order)
end

#find_by_id(id) ⇒ Object



15
16
17
# File 'lib/pact_broker/pacticipants/repository.rb', line 15

def find_by_id id
  PactBroker::Domain::Pacticipant.where(id: id).single_record
end

#find_by_name(name) ⇒ Object



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

def find_by_name name
  PactBroker::Domain::Pacticipant.where(name_like(:name, name)).single_record
end

#find_by_name_or_create(name) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/pact_broker/pacticipants/repository.rb', line 36

def find_by_name_or_create name
  if pacticipant = find_by_name(name)
    pacticipant
  else
    create name: name
  end
end

#pacticipant_namesObject



48
49
50
# File 'lib/pact_broker/pacticipants/repository.rb', line 48

def pacticipant_names
  PactBroker::Domain::Pacticipant.select(:name).order(:name).collect{ | pacticipant| pacticipant.name }
end