Class: Mrt::Ingest::IObject
- Inherits:
-
Object
- Object
- Mrt::Ingest::IObject
- Defined in:
- lib/mrt/ingest/iobject.rb
Overview
An object prepared for ingest into Merritt.
Instance Attribute Summary collapse
-
#erc ⇒ Object
Returns the value of attribute erc.
-
#local_identifier ⇒ Object
Returns the value of attribute local_identifier.
-
#primary_identifier ⇒ Object
Returns the value of attribute primary_identifier.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
-
#add_component(where, options = {}) ⇒ Object
Add a component to the object.
-
#finish_ingest ⇒ Object
Wait for the ingest of this object to finish.
-
#initialize(options = {}) ⇒ IObject
constructor
Options can have the keys :primary_identifier, :local_identifier, :server, or :erc.
-
#join_server ⇒ Object
:nodoc:.
-
#mk_manifest(manifest, erc_component) ⇒ Object
rubocop:disable Metrics/LineLength.
-
#mk_request(profile, user_agent) ⇒ Object
Make a Mrt::Ingest::Request object for this mrt-object.
-
#start_ingest(client, profile, submitter) ⇒ Object
Begin an ingest on the given client, with a profile and submitter.
-
#start_server ⇒ Object
:nodoc:.
-
#stop_server ⇒ Object
:nodoc:.
Constructor Details
#initialize(options = {}) ⇒ IObject
Options can have the keys :primary_identifier, :local_identifier, :server, or :erc. :erc can be a #File, #Uri or a #Hash of metadata. :server is a #OneTimeServer.
21 22 23 24 25 26 27 |
# File 'lib/mrt/ingest/iobject.rb', line 21 def initialize( = {}) @primary_identifier = [:primary_identifier] @local_identifier = [:local_identifier] @erc = [:erc] || {} @components = [] @server = [:server] || Mrt::Ingest::OneTimeServer.new end |
Instance Attribute Details
#erc ⇒ Object
Returns the value of attribute erc.
15 16 17 |
# File 'lib/mrt/ingest/iobject.rb', line 15 def erc @erc end |
#local_identifier ⇒ Object
Returns the value of attribute local_identifier.
15 16 17 |
# File 'lib/mrt/ingest/iobject.rb', line 15 def local_identifier @local_identifier end |
#primary_identifier ⇒ Object
Returns the value of attribute primary_identifier.
15 16 17 |
# File 'lib/mrt/ingest/iobject.rb', line 15 def primary_identifier @primary_identifier end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
16 17 18 |
# File 'lib/mrt/ingest/iobject.rb', line 16 def server @server end |
Instance Method Details
#add_component(where, options = {}) ⇒ Object
Add a component to the object. where can be either a #URI or a #File. Options is a hash whose keys may be :name, :digest, :mime_type, or :size. If :digest is supplied, it must be a subclass of Mrt::Ingest::MessageDigest::Base. If where is a #File, it will be hosted on an embedded web server.
34 35 36 |
# File 'lib/mrt/ingest/iobject.rb', line 34 def add_component(where, = {}) @components.push(Component.new(@server, where, )) end |
#finish_ingest ⇒ Object
Wait for the ingest of this object to finish.
84 85 86 87 88 |
# File 'lib/mrt/ingest/iobject.rb', line 84 def finish_ingest # XXX Right now we only join the hosting server; in the future # we will check the status via the ingest server. join_server end |
#join_server ⇒ Object
:nodoc:
52 53 54 |
# File 'lib/mrt/ingest/iobject.rb', line 52 def join_server # :nodoc: @server.join_server end |
#mk_manifest(manifest, erc_component) ⇒ Object
rubocop:disable Metrics/LineLength
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/mrt/ingest/iobject.rb', line 61 def mk_manifest(manifest, erc_component) # :nodoc: manifest.write("#%checkm_0.7\n") manifest.write("#%profile http://uc3.cdlib.org/registry/ingest/manifest/mrt-ingest-manifest\n") manifest.write("#%prefix | mrt: | http://uc3.cdlib.org/ontology/mom#\n") manifest.write("#%prefix | nfo: | http://www.semanticdesktop.org/ontologies/2007/03/22/nfo#\n") manifest.write("#%fields | nfo:fileUrl | nfo:hashAlgorithm | nfo:hashValue | nfo:fileSize | nfo:fileLastModified | nfo:fileName | mrt:mimeType\n") @components.each do |c| manifest.write(c.to_manifest_entry) end manifest.write(erc_component.to_manifest_entry) manifest.write("#%EOF\n") end |
#mk_request(profile, user_agent) ⇒ Object
Make a Mrt::Ingest::Request object for this mrt-object
39 40 41 42 43 44 45 46 |
# File 'lib/mrt/ingest/iobject.rb', line 39 def mk_request(profile, user_agent) manifest_file = Tempfile.new('mrt-ingest') erc_component = Component.from_erc(@server, @erc) mk_manifest(manifest_file, erc_component) # reset to beginning manifest_file.open new_request(manifest_file, profile, user_agent) end |
#start_ingest(client, profile, submitter) ⇒ Object
Begin an ingest on the given client, with a profile and submitter.
77 78 79 80 81 |
# File 'lib/mrt/ingest/iobject.rb', line 77 def start_ingest(client, profile, submitter) request = mk_request(profile, submitter) start_server @response = client.ingest(request) end |
#start_server ⇒ Object
:nodoc:
48 49 50 |
# File 'lib/mrt/ingest/iobject.rb', line 48 def start_server # :nodoc: @server.start_server end |
#stop_server ⇒ Object
:nodoc:
56 57 58 |
# File 'lib/mrt/ingest/iobject.rb', line 56 def stop_server # :nodoc: @server.stop_server end |