Class: Stash::Harvester::Resync::ResyncRecord

Inherits:
HarvestedRecord show all
Defined in:
lib/stash/harvester/resync/resync_record.rb

Overview

A utility wrapper around Resync::Resource that includes both the resource and the content of the resource

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource) ⇒ ResyncRecord

Creates a new Stash::Harvester::Resync::ResyncRecord wrapping the specified resource. The resource is responsible for providing its own content; any resource provided by a Resync::Client should be able to do this.

Parameters:

  • resource (Resync::Resource with Resync::Client::Mixins::Downloadable, Resync::Client::Mixins::BitstreamResource)

    the resource


28
29
30
31
32
33
34
35
36
37
38
# File 'lib/stash/harvester/resync/resync_record.rb', line 28

def initialize(resource)
  super(
    identifier: resource.uri.to_s,
    timestamp: resource.modified_time,
    deleted: begin
       = resource.
       && .change == ::Resync::Types::Change::DELETED
    end
  )
  @resource = resource
end

Instance Attribute Details

#deletedBoolean (readonly)

Returns True if this change indicates a deletion, false otherwise.

Returns:

  • (Boolean)

    True if this change indicates a deletion, false otherwise.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/stash/harvester/resync/resync_record.rb', line 20

class ResyncRecord < Stash::Harvester::HarvestedRecord

  # Creates a new {ResyncRecord} wrapping the specified resource. The resource
  # is responsible for providing its own content; any resource provided by a
  # {http://www.rubydoc.info/github/dmolesUC3/resync-client/Resync/Client Resync::Client} should be able to do this.
  #
  # @param resource [Resync::Resource with Resync::Client::Mixins::Downloadable, Resync::Client::Mixins::BitstreamResource]
  #   the resource
  def initialize(resource)
    super(
      identifier: resource.uri.to_s,
      timestamp: resource.modified_time,
      deleted: begin
         = resource.
         && .change == ::Resync::Types::Change::DELETED
      end
    )
    @resource = resource
  end

  # The content of the resource, as retrieved from the resource URL, or from
  # the containing ZIP bitstream package if one is available
  #
  # @return [String] the content of the resource
  def content
    @content ||= @deleted ? nil : content_from(@resource)
  end

  private

  def content_from(resource)
    if resource.respond_to?(:bitstream)
      bitstream = resource.bitstream
      bitstream.content
    elsif resource.respond_to?(:get)
      resource.get
    end
  end
end

#identifierString (readonly)

Returns The URI of the record.

Returns:

  • (String)

    The URI of the record.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/stash/harvester/resync/resync_record.rb', line 20

class ResyncRecord < Stash::Harvester::HarvestedRecord

  # Creates a new {ResyncRecord} wrapping the specified resource. The resource
  # is responsible for providing its own content; any resource provided by a
  # {http://www.rubydoc.info/github/dmolesUC3/resync-client/Resync/Client Resync::Client} should be able to do this.
  #
  # @param resource [Resync::Resource with Resync::Client::Mixins::Downloadable, Resync::Client::Mixins::BitstreamResource]
  #   the resource
  def initialize(resource)
    super(
      identifier: resource.uri.to_s,
      timestamp: resource.modified_time,
      deleted: begin
         = resource.
         && .change == ::Resync::Types::Change::DELETED
      end
    )
    @resource = resource
  end

  # The content of the resource, as retrieved from the resource URL, or from
  # the containing ZIP bitstream package if one is available
  #
  # @return [String] the content of the resource
  def content
    @content ||= @deleted ? nil : content_from(@resource)
  end

  private

  def content_from(resource)
    if resource.respond_to?(:bitstream)
      bitstream = resource.bitstream
      bitstream.content
    elsif resource.respond_to?(:get)
      resource.get
    end
  end
end

#metadata_rootREXML::Element (readonly)

Returns The root (inner) element of the record metadata.

Returns:

  • (REXML::Element)

    The root (inner) element of the record metadata.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/stash/harvester/resync/resync_record.rb', line 20

class ResyncRecord < Stash::Harvester::HarvestedRecord

  # Creates a new {ResyncRecord} wrapping the specified resource. The resource
  # is responsible for providing its own content; any resource provided by a
  # {http://www.rubydoc.info/github/dmolesUC3/resync-client/Resync/Client Resync::Client} should be able to do this.
  #
  # @param resource [Resync::Resource with Resync::Client::Mixins::Downloadable, Resync::Client::Mixins::BitstreamResource]
  #   the resource
  def initialize(resource)
    super(
      identifier: resource.uri.to_s,
      timestamp: resource.modified_time,
      deleted: begin
         = resource.
         && .change == ::Resync::Types::Change::DELETED
      end
    )
    @resource = resource
  end

  # The content of the resource, as retrieved from the resource URL, or from
  # the containing ZIP bitstream package if one is available
  #
  # @return [String] the content of the resource
  def content
    @content ||= @deleted ? nil : content_from(@resource)
  end

  private

  def content_from(resource)
    if resource.respond_to?(:bitstream)
      bitstream = resource.bitstream
      bitstream.content
    elsif resource.respond_to?(:get)
      resource.get
    end
  end
end

#timestampTime (readonly)

Returns The modification time of the resource.

Returns:

  • (Time)

    The modification time of the resource.


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/stash/harvester/resync/resync_record.rb', line 20

class ResyncRecord < Stash::Harvester::HarvestedRecord

  # Creates a new {ResyncRecord} wrapping the specified resource. The resource
  # is responsible for providing its own content; any resource provided by a
  # {http://www.rubydoc.info/github/dmolesUC3/resync-client/Resync/Client Resync::Client} should be able to do this.
  #
  # @param resource [Resync::Resource with Resync::Client::Mixins::Downloadable, Resync::Client::Mixins::BitstreamResource]
  #   the resource
  def initialize(resource)
    super(
      identifier: resource.uri.to_s,
      timestamp: resource.modified_time,
      deleted: begin
         = resource.
         && .change == ::Resync::Types::Change::DELETED
      end
    )
    @resource = resource
  end

  # The content of the resource, as retrieved from the resource URL, or from
  # the containing ZIP bitstream package if one is available
  #
  # @return [String] the content of the resource
  def content
    @content ||= @deleted ? nil : content_from(@resource)
  end

  private

  def content_from(resource)
    if resource.respond_to?(:bitstream)
      bitstream = resource.bitstream
      bitstream.content
    elsif resource.respond_to?(:get)
      resource.get
    end
  end
end

Instance Method Details

#contentString

The content of the resource, as retrieved from the resource URL, or from the containing ZIP bitstream package if one is available

Returns:

  • (String)

    the content of the resource


44
45
46
# File 'lib/stash/harvester/resync/resync_record.rb', line 44

def content
  @content ||= @deleted ? nil : content_from(@resource)
end