Sha256: a76598c4983f16f8d8346b0a5d8680d2e83ea0b9c6903f85ce5f3daaf01fe29e

Contents?: true

Size: 811 Bytes

Versions: 12

Compression:

Stored size: 811 Bytes

Contents

# frozen_string_literal: true

module Dor
  # Adds and removes collections to and from objects
  # Collections are added as Collections and Sets.
  class CollectionService
    def initialize(obj)
      @obj = obj
    end

    def add(collection_or_druid)
      collection = dereference(collection_or_druid)
      obj.collections << collection
      obj.sets << collection
    end

    def remove(collection_or_druid)
      collection = dereference(collection_or_druid)
      obj.collections.delete(collection)
      obj.sets.delete(collection)
    end

    private

    attr_reader :obj

    def dereference(collection_or_druid)
      case collection_or_druid
      when String
        Dor::Collection.find(collection_or_druid)
      when Dor::Collection
        collection_or_druid
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
dor-services-9.6.2 lib/dor/services/collection_service.rb
dor-services-9.6.1 lib/dor/services/collection_service.rb
dor-services-9.6.0 lib/dor/services/collection_service.rb
dor-services-9.5.0 lib/dor/services/collection_service.rb
dor-services-9.4.0 lib/dor/services/collection_service.rb
dor-services-9.3.0 lib/dor/services/collection_service.rb
dor-services-9.2.1 lib/dor/services/collection_service.rb
dor-services-9.2.0 lib/dor/services/collection_service.rb
dor-services-9.1.0 lib/dor/services/collection_service.rb
dor-services-9.0.0 lib/dor/services/collection_service.rb
dor-services-8.6.0 lib/dor/services/collection_service.rb
dor-services-8.5.0 lib/dor/services/collection_service.rb