Sha256: 4f08ef4a35f75109fa00a614e64543d3b053a2c14bdfc74ce0fb626496138ca5

Contents?: true

Size: 1.6 KB

Versions: 17

Compression:

Stored size: 1.6 KB

Contents

require 'sequel'
require 'pact_broker/domain/version'
require 'pact_broker/tags/repository'

module PactBroker
  module Versions
    class Repository

      include PactBroker::Repositories::Helpers

      def find_by_pacticipant_id_and_number pacticipant_id, number
        PactBroker::Domain::Version.where(number: number, pacticipant_id: pacticipant_id).single_record
      end

      def find_by_pacticipant_name_and_number pacticipant_name, number
        PactBroker::Domain::Version
          .select(Sequel[:versions][:id], Sequel[:versions][:number], Sequel[:versions][:pacticipant_id], Sequel[:versions][:order], Sequel[:versions][:created_at], Sequel[:versions][:updated_at])
          .join(:pacticipants, {id: :pacticipant_id})
          .where(name_like(:number, number))
          .where(name_like(:name, pacticipant_name))
          .single_record
      end

      def create args
        PactBroker.logger.info "Creating version #{args[:number]} for pacticipant_id=#{args[:pacticipant_id]}"
        version = PactBroker::Domain::Version.new(number: args[:number], pacticipant_id: args[:pacticipant_id]).save
        PactBroker::Domain::Version.find(id: version.id) # Need to reload with populated order
      end

      def find_by_pacticipant_id_and_number_or_create pacticipant_id, number
        if version = find_by_pacticipant_id_and_number(pacticipant_id, number)
          version
        else
          create(pacticipant_id: pacticipant_id, number: number)
        end
      end

      def delete_by_id version_ids
        Sequel::Model.db[:versions].where(id: version_ids).delete
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
pact_broker-2.7.0.beta.2 lib/pact_broker/versions/repository.rb
pact_broker-2.7.0.beta.1 lib/pact_broker/versions/repository.rb
pact_broker-2.6.0 lib/pact_broker/versions/repository.rb
pact_broker-2.5.1 lib/pact_broker/versions/repository.rb
pact_broker-2.5.0 lib/pact_broker/versions/repository.rb
pact_broker-2.4.2 lib/pact_broker/versions/repository.rb
pact_broker-2.4.1 lib/pact_broker/versions/repository.rb
pact_broker-2.4.0 lib/pact_broker/versions/repository.rb
pact_broker-2.3.0 lib/pact_broker/versions/repository.rb
pact_broker-2.2.0 lib/pact_broker/versions/repository.rb
pact_broker-2.1.1 lib/pact_broker/versions/repository.rb
pact_broker-2.1.0 lib/pact_broker/versions/repository.rb
pact_broker-2.0.5 lib/pact_broker/versions/repository.rb
pact_broker-2.0.4 lib/pact_broker/versions/repository.rb
pact_broker-2.0.3 lib/pact_broker/versions/repository.rb
pact_broker-2.0.2 lib/pact_broker/versions/repository.rb
pact_broker-2.0.1 lib/pact_broker/versions/repository.rb