Sha256: 57f1285e0bdbc6134dc890c0f9e35ec5f294d50b536a3bd45e6809e3314822f3
Contents?: true
Size: 1.81 KB
Versions: 1
Compression:
Stored size: 1.81 KB
Contents
module IMW class Metadata # 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. module ContainsMetadata # 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. # # @return [String, nil] def default_metadata_uri contents.detect { |path| path =~ /(icss|metadata).*\.(ya?ml|json)$/i } || File.join(path, "#{basename}.icss.yaml") end # Return the metadata for this resource if it exists. # # Will look for an existing resource at +default_metadata_uri+. # # @return [IMW::Metadata, nil] def metadata return @metadata if @metadata obj = IMW.open(default_metadata_uri) self.metadata=(obj) if obj.exist? @metadata end # Set the metadata for this resource to +obj+. # # @param [String, Addressable::URI, IMW::Resource] obj def metadata= obj @metadata = IMW::Metadata.load(obj) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
imw-0.2.17 | lib/imw/metadata/contains_metadata.rb |