lib/data_paths/methods.rb in data_paths-0.2.1 vs lib/data_paths/methods.rb in data_paths-0.3.0.rc1

- old
+ new

@@ -1,17 +1,15 @@ -require 'set' - module DataPaths module Methods # # The directories registered within a specific module or class. # - # @return [Set] + # @return [Array<String>] # The directories registered so far. # def data_paths - @data_paths ||= Set[] + @data_paths ||= [] end # # Registers a path as a data directory. # @@ -25,46 +23,77 @@ # register_data_dir File.join(File.dirname(__FILE__),'..','..','..','data') # # @raise [RuntimeError] # The specified path is not a directory. # - def register_data_dir(path) - path = File.expand_path(path) + # @since 0.3.0 + # + def register_data_path(path) + DataPaths.register(path) - unless File.directory?(path) - raise(RuntimeError,"#{path.dump} must be a directory") - end + data_paths << path unless data_paths.include?(path) + return path + end - self.data_paths << path + # + # @deprecated + # Will be removed 1.0.0, please use {#register_data_path} instead. + # + def register_data_dir(path) + STDERR.puts "DEPRECATED: Please use register_data_path instead." - DataPaths.paths << path - return path + register_data_path(path) end # # Unregisters any matching data directories. # # @param [String] path - # The path to unregistere. + # The path to unregister. # - # @return [true] + # @return [String] + # The unregistered data path. # - def unregister_data_dir!(path) + # @since 0.3.0 + # + def unregister_data_path(path) path = File.expand_path(path) - self.data_paths.reject! { |dir| dir == path } - DataPaths.paths.reject! { |dir| dir == path } - return true + self.data_paths.delete(path) + return DataPaths.unregister!(path) end # + # @deprecated + # Will be removed 1.0.0, please use {#unregister_data_path} instead. + # + def unregister_data_dir!(path) + STDERR.puts "DEPRECATED: Please use unregister_data_path instead." + + unregister_data_path(path) + end + + # # Unregisters all previously registered data directories. # # @return [true] + # Specifies all data paths were successfully unregistered. # - def unregister_data_dirs! - DataPaths.paths.reject! { |dir| self.data_paths.include?(dir) } - self.data_paths.clear + # @since 0.3.0 + # + def unregister_data_paths + data_paths.each { |path| DataPaths.unregister!(path) } + data_paths.clear return true + end + + # + # @deprecated + # Will be removed 1.0.0, please use {#unregister_data_paths} instead. + # + def unregister_data_dirs! + STDERR.puts "DEPRECATED: Please use unregister_data_paths instead." + + unregister_data_paths end end end