require 'repertoire/media/extensions/meta' require 'repertoire/media/media' require 'repertoire/compat' module Repertoire module Media class Type # # The name of the Media Type. # def self.name nil end # # The supports URI schemes of the Media Type. # def self.schemes [] end # # The directory which is used by the Media Type to store metadata. # def self.directory nil end protected # # Register a Media type with a given names. # # @param [Symbol, String] name # The name to give the media type. # # @example # known_as :svn # def self.known_as(name) name = name.to_sym meta_def(:name) { name } Media.types[name] = self end # # Register a Media type for given schemes. # # @param [Array] schemes # The URI schemes supported by the media type. # # @example # uses_schemes 'svn' # # @example # uses_schemes 'svn', 'svn+ssh' # def self.uses_schemes(*schemes) meta_def(:schemes) { schemes } schemes.each do |scheme| scheme = scheme.to_s Media.schemes[scheme] = self end end # # Registers a Media type that uses a given directory name for storage. # # @param [String] name # The media storage directory used by the media type. # # @example # uses_directory '.svn' # def self.uses_directory(name) name = name.to_s meta_def(:directory) { name } Media.directories[name] = self end # # Changes the current working directory. # # @param [String] path # The directory to change to. # # @see http://www.ruby-doc.org/core/classes/Dir.html#M002314 # def self.cd(path) Dir.chdir(path.to_s) end # # Changes the current working directory, calls a given block, then # changes the current working directory back. # # @param [String] path # The directory to temporarily switch to. # # @yield [] # If a block is given, it will be called after the current working # directory has been changed. # def self.switch_dir(path,&block) current = Dir.pwd cd path block.call if block cd current end # # @see Compat.sh. # def self.sh(program,*args) Compat.sh(program,*args) end end end end