Sha256: 9852430230f3e368f2eb25da9dfb9828c1447c337afc77046c69f169c79831a3

Contents?: true

Size: 1.42 KB

Versions: 1

Compression:

Stored size: 1.42 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
        PactBroker::Domain::Pacticipant.order(:name).all
      end

      def find_all_pacticipant_versions_in_reverse_order name
        PactBroker::Domain::Version
          .select(:versions__id, :versions__number, :versions__pacticipant_id, :versions__order, :versions__created_at, :versions__updated_at)
          .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

      def find_latest_version name

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pact_broker-1.18.0 lib/pact_broker/pacticipants/repository.rb