Module: IMW::Metadata::ContainsMetadata

Included in:
Schemes::Local::LocalDirectory
Defined in:
lib/imw/metadata/contains_metadata.rb

Overview

A module for finding metadata describing the sub-resources of a given resource.

An including class describing the parent resource must define the contents method which must return an Array of Strings contained within the parent . These objects will be matched against possible metadata URIs and the corresponding IMW::Metadata class created on the fly.

In case no such object is found, the class should also define the basename and path methods which will be used to generate a default URI where metadata about the parent’s resources should live.

Instance Method Summary collapse

Instance Method Details

#default_metadata_uriString?

The URI containing the metadata for this resource and its contents.

Looks for an existing JSON or YAML file containing the strings “icss” or “metadata” directly contained within this resource.

If none are found, defaults to a URI named after this resource’s basename with the string “.icss.yaml” appended.

Returns:



29
30
31
# File 'lib/imw/metadata/contains_metadata.rb', line 29

def 
  contents.detect { |path| path =~ /(icss|metadata).*\.(ya?ml|json)$/i } || File.join(path, "#{basename}.icss.yaml")
end

#metadataIMW::Metadata?

Return the metadata for this resource if it exists.

Will look for an existing resource at default_metadata_uri.

Returns:



38
39
40
41
42
43
# File 'lib/imw/metadata/contains_metadata.rb', line 38

def 
  return @metadata if @metadata
  obj = IMW.open()
  self.=(obj) if obj.exist?
  @metadata
end

#metadata=(obj) ⇒ Object

Set the metadata for this resource to obj.

Parameters:



48
49
50
# File 'lib/imw/metadata/contains_metadata.rb', line 48

def metadata= obj
  @metadata = IMW::Metadata.load(obj)
end