class ROBundle::Manifest
The manifest.json managed file entry for a Research Object.
Public Class Methods
Create a new managed file entry to represent the manifest.json file.
# File lib/ro-bundle/ro/manifest.rb, line 24 def initialize super(FILE_NAME, :required => true) @edited = false end
Public Instance Methods
Add the given entry or URI to the list of aggregates in this manifest.
Errno:ENOENT
is raised if the entry does not exist.
The Aggregate object added to the Research Object is returned.
# File lib/ro-bundle/ro/manifest.rb, line 107 def add_aggregate(entry) unless entry.instance_of?(Aggregate) unless Util.is_absolute_uri?(entry) raise Errno::ENOENT if container.find_entry(entry).nil? end entry = Aggregate.new(entry) end @edited = true structure[:aggregates] << entry entry end
Add an annotation to this Research Object. An annotation can either be an already created annotation object, or a pair of values to build a new annotation object explicitly.
Errno:ENOENT
is raised if the target of the annotation is not
an annotatable resource in this RO.
The Annotation object added to the Research Object is returned.
# File lib/ro-bundle/ro/manifest.rb, line 163 def add_annotation(object, content = nil) if object.instance_of?(Annotation) # If the supplied Annotation object is already registered then it is # the annotation itself we are annotating! if container.annotation?(object) object = Annotation.new(object.annotation_id, content) end else object = Annotation.new(object, content) end target = object.target unless container.annotatable?(target) raise Errno::ENOENT, "'#{target}' is not a member of this Research Object or a URI." end @edited = true structure[:annotations] << object object end
Add a URI to the front of the @context list.
# File lib/ro-bundle/ro/manifest.rb, line 42 def add_context(uri) @edited = true structure[:@context].insert(0, uri.to_s) end
Add the given entry to the history list in this manifest.
Errno:ENOENT
is raised if the entry does not exist.
# File lib/ro-bundle/ro/manifest.rb, line 79 def add_history(entry) raise Errno::ENOENT if container.find_entry(entry).nil? # Mangle the filename according to the RO Bundle specification. name = entry_name(entry) dir = "#{@parent.full_name}/" name = name.start_with?(dir) ? name.sub(dir, "") : "/#{name}" @edited = true structure[:history] << name end
Return a list of all the aggregated resources in this Research Object.
# File lib/ro-bundle/ro/manifest.rb, line 95 def aggregates structure[:aggregates].dup end
Return a list of all the annotations in this Research Object.
# File lib/ro-bundle/ro/manifest.rb, line 214 def annotations structure[:annotations].dup end
Return the list of @context URIs for this Research Object manifest.
# File lib/ro-bundle/ro/manifest.rb, line 34 def context structure[:@context].dup end
Has this manifest been altered in any way?
# File lib/ro-bundle/ro/manifest.rb, line 222 def edited? @edited end
Return a list of filenames that hold provenance information for this Research Object.
# File lib/ro-bundle/ro/manifest.rb, line 70 def history structure[:history].dup end
An RO identifier (usually ‘/’) indicating the relative top-level folder as the identifier.
# File lib/ro-bundle/ro/manifest.rb, line 52 def id structure[:id] end
Set the id of this Manifest.
# File lib/ro-bundle/ro/manifest.rb, line 60 def id=(new_id) @edited = true structure[:id] = new_id end
Remove (unregister) an aggregate from this Research Object. If a filename is supplied then the file is no longer aggregated, but it is not deleted from the bundle by this method.
Any annotations with the removed aggregate as their target are also removed from the RO.
# File lib/ro-bundle/ro/manifest.rb, line 132 def remove_aggregate(object) removed = nil if object.is_a?(Aggregate) removed = structure[:aggregates].delete(object) unless removed.nil? removed = removed.file.nil? ? removed.uri : removed.file end else removed = remove_aggregate_by_file_or_uri(object) end unless removed.nil? remove_annotation(removed) @edited = true end end
Remove (unregister) annotations from this Research Object and return them.
Return nil
if the annotation does not exist.
Any annotation content that is stored in the .ro/annotations directory is automatically cleaned up when the RO is closed.
# File lib/ro-bundle/ro/manifest.rb, line 195 def remove_annotation(object) if object.is_a?(Annotation) removed = [structure[:annotations].delete(object)].compact else removed = remove_annotation_by_field(object) end removed.each do |ann| id = ann.annotation_id remove_annotation(id) unless id.nil? end @edited = true unless removed.empty? end
Write this Manifest out as a json string. Takes the same options as JSON#generate.
# File lib/ro-bundle/ro/manifest.rb, line 231 def to_json(*a) Util.clean_json(structure).to_json(*a) end
Protected Instance Methods
Validate the correctness of the manifest file contents.
# File lib/ro-bundle/ro/manifest.rb, line 241 def validate begin structure rescue JSON::ParserError, ROError return false end true end