Sha256: 8e0a332d6b1600d3f64c5f0fb566325fb60c4622d6c3dc61126df696efd9910d

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

module FedoraMigrate
  class Mover
    include MigrationOptions
    include Hooks

    attr_accessor :target, :source, :report

    def initialize(*args)
      @source = args[0]
      @target = args[1]
      @options = args[2]
      @report = results_report
      post_initialize
    end

    def post_initialize
    end

    def results_report
      []
    end

    def migrate
      report
    end

    def save
      raise FedoraMigrate::Errors::MigrationError, "Failed to save target: #{target_errors}" unless target.save
    end

    def target_errors
      if target.respond_to?(:errors)
        target.errors.full_messages.join(" -- ")
      else
        target.inspect
      end
    end

    def id_component(object = nil)
      object ||= source
      raise FedoraMigrate::Errors::MigrationError, "can't get the id component without an object" if object.nil?
      self.class.id_component(object)
    end

    def self.id_component(object)
      return object.pid.split(/:/).last if object.is_a?(Rubydora::DigitalObject)
      return object.to_s.split(/:/).last if object.respond_to?(:to_s)
      nil
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fedora-migrate-0.5.0 lib/fedora_migrate/mover.rb
fedora-migrate-0.4.0 lib/fedora_migrate/mover.rb