Sha256: 4b5fc1e5781004b8f3e656a8fd0d4cd828f7b9464fab5f09b952c4dc19f3c1d7

Contents?: true

Size: 1.46 KB

Versions: 39

Compression:

Stored size: 1.46 KB

Contents

require 'sequel'
require 'pact_broker/domain/pacticipant'
require 'pact_broker/repositories/helpers'

module PactBroker
  module Pacticipants
    class Repository

      include PactBroker::Repositories::Helpers

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

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

      def find_all
        find
      end

      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

      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

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

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

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

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
pact_broker-2.26.0 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.25.0 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.24.0 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.23.4 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.23.3 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.23.2 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.23.1 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.23.0 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.22.0 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.21.0 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.20.0 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.19.2 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.19.1 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.19.0 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.18.0 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.17.1 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.17.0 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.16.1 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.16.0 lib/pact_broker/pacticipants/repository.rb
pact_broker-2.15.0 lib/pact_broker/pacticipants/repository.rb