Sha256: ad482bbdc13c0de38976d242927a083e09830d5c52a5d57da8a59256f84a7320

Contents?: true

Size: 1.67 KB

Versions: 43

Compression:

Stored size: 1.67 KB

Contents

require 'pact_broker/domain/tag'
require 'pact_broker/repositories/helpers'

module PactBroker
  module Tags
    class Repository

      include PactBroker::Repositories::Helpers

      def create args
        params = {
          name: args.fetch(:name),
          version_id: args.fetch(:version).id,
          created_at: Sequel.datetime_class.now,
          updated_at: Sequel.datetime_class.now
        }
        Domain::Tag.dataset.insert_ignore.insert(params)
        Domain::Tag.find(name: args[:name], version_id: args[:version].id)
      end

      def find args
        PactBroker::Domain::Tag
          .select_all_qualified
          .join(:versions, { id: :version_id })
          .join(:pacticipants, {Sequel.qualify("pacticipants", "id") => Sequel.qualify("versions", "pacticipant_id")})
          .where(name_like(Sequel.qualify("tags", "name"), args.fetch(:tag_name)))
          .where(name_like(Sequel.qualify("versions", "number"), args.fetch(:pacticipant_version_number)))
          .where(name_like(Sequel.qualify("pacticipants", "name"), args.fetch(:pacticipant_name)))
          .single_record
      end

      def delete_by_version_id version_id
        Domain::Tag.where(version_id: version_id).delete
      end

      def find_all_tag_names_for_pacticipant pacticipant_name
        PactBroker::Domain::Tag
        .select(Sequel[:tags][:name])
        .join(:versions, { Sequel[:versions][:id] => Sequel[:tags][:version_id] })
        .join(:pacticipants, { Sequel[:pacticipants][:id] => Sequel[:versions][:pacticipant_id] })
        .where(Sequel[:pacticipants][:name] => pacticipant_name)
        .distinct
        .collect{ |tag| tag[:name] }.sort
      end
    end
  end
end

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
pact_broker-2.65.0 lib/pact_broker/tags/repository.rb
pact_broker-2.64.0 lib/pact_broker/tags/repository.rb
pact_broker-2.63.0 lib/pact_broker/tags/repository.rb
pact_broker-2.62.0 lib/pact_broker/tags/repository.rb
pact_broker-2.61.0 lib/pact_broker/tags/repository.rb
pact_broker-2.60.1 lib/pact_broker/tags/repository.rb
pact_broker-2.60.0 lib/pact_broker/tags/repository.rb
pact_broker-2.59.2 lib/pact_broker/tags/repository.rb
pact_broker-2.59.1 lib/pact_broker/tags/repository.rb
pact_broker-2.59.0 lib/pact_broker/tags/repository.rb
pact_broker-2.58.3 lib/pact_broker/tags/repository.rb
pact_broker-2.58.2 lib/pact_broker/tags/repository.rb
pact_broker-2.58.0 lib/pact_broker/tags/repository.rb
pact_broker-2.57.0 lib/pact_broker/tags/repository.rb
pact_broker-2.56.1 lib/pact_broker/tags/repository.rb
pact_broker-2.56.0 lib/pact_broker/tags/repository.rb
pact_broker-2.55.0 lib/pact_broker/tags/repository.rb
pact_broker-2.54.0 lib/pact_broker/tags/repository.rb
pact_broker-2.53.0 lib/pact_broker/tags/repository.rb
pact_broker-2.52.2 lib/pact_broker/tags/repository.rb