deprecate GridFS::GridStore and GridFS::Chunk

This commit is contained in:
Kyle Banker 2010-02-23 16:19:45 -05:00
parent ffd8d5f6a3
commit 15ee9530ed
2 changed files with 16 additions and 0 deletions

View File

@ -21,6 +21,7 @@ require 'mongo/util/ordered_hash'
module GridFS module GridFS
# A chunk stores a portion of GridStore data. # A chunk stores a portion of GridStore data.
# @deprecated
class Chunk class Chunk
DEFAULT_CHUNK_SIZE = 1024 * 256 DEFAULT_CHUNK_SIZE = 1024 * 256

View File

@ -48,6 +48,7 @@ module GridFS
# end # end
# #
# @core gridfs # @core gridfs
# @deprecated
class GridStore class GridStore
include Enumerable include Enumerable
@ -55,6 +56,8 @@ module GridFS
DEFAULT_CONTENT_TYPE = 'text/plain' DEFAULT_CONTENT_TYPE = 'text/plain'
DEPRECATION_WARNING = "GridFS::GridStore is deprecated. Use either Grid or GridFileSystem."
attr_accessor :filename attr_accessor :filename
# Array of strings; may be +nil+ # Array of strings; may be +nil+
@ -94,7 +97,9 @@ module GridFS
# @param [String] root_collection the name of the gridfs root collection. # @param [String] root_collection the name of the gridfs root collection.
# #
# @return [Boolean] # @return [Boolean]
# @deprecated
def self.exist?(db, name, root_collection=GridStore.default_root_collection) def self.exist?(db, name, root_collection=GridStore.default_root_collection)
warn DEPRECATION_WARNING
db.collection("#{root_collection}.files").find({'filename' => name}).next_document != nil db.collection("#{root_collection}.files").find({'filename' => name}).next_document != nil
end end
@ -110,6 +115,7 @@ module GridFS
# #
# @see GridStore#initialize. # @see GridStore#initialize.
# @see The various GridStore class methods, e.g., GridStore.open, GridStore.read etc. # @see The various GridStore class methods, e.g., GridStore.open, GridStore.read etc.
# @deprecated
def self.open(db, name, mode, options={}) def self.open(db, name, mode, options={})
gs = self.new(db, name, mode, options) gs = self.new(db, name, mode, options)
result = nil result = nil
@ -130,6 +136,7 @@ module GridFS
# beginning of the file to start reading. # beginning of the file to start reading.
# #
# @return [String] the file data # @return [String] the file data
# @deprecated
def self.read(db, name, length=nil, offset=nil) def self.read(db, name, length=nil, offset=nil)
GridStore.open(db, name, 'r') do |gs| GridStore.open(db, name, 'r') do |gs|
gs.seek(offset) if offset gs.seek(offset) if offset
@ -144,7 +151,9 @@ module GridFS
# @param [String] root_collection the name of the root collection. # @param [String] root_collection the name of the root collection.
# #
# @return [Array] # @return [Array]
# @deprecated
def self.list(db, root_collection=GridStore.default_root_collection) def self.list(db, root_collection=GridStore.default_root_collection)
warn DEPRECATION_WARNING
db.collection("#{root_collection}.files").find().map do |f| db.collection("#{root_collection}.files").find().map do |f|
f['filename'] f['filename']
end end
@ -158,6 +167,7 @@ module GridFS
# @param [String, Reg] separator # @param [String, Reg] separator
# #
# @return [Array] # @return [Array]
# @deprecated
def self.readlines(db, name, separator=$/) def self.readlines(db, name, separator=$/)
GridStore.open(db, name, 'r') do |gs| GridStore.open(db, name, 'r') do |gs|
gs.readlines(separator) gs.readlines(separator)
@ -170,6 +180,7 @@ module GridFS
# @param [Array<String>] names the filenames to remove # @param [Array<String>] names the filenames to remove
# #
# @return [True] # @return [True]
# @deprecated
def self.unlink(db, *names) def self.unlink(db, *names)
names.each do |name| names.each do |name|
gs = GridStore.new(db, name) gs = GridStore.new(db, name)
@ -189,7 +200,9 @@ module GridFS
# @param [String] src the name of the source file. # @param [String] src the name of the source file.
# @param [String] dest the name of the destination file. # @param [String] dest the name of the destination file.
# @param [String] root_collection the name of the default root collection. # @param [String] root_collection the name of the default root collection.
# @deprecated
def self.mv(db, src, dest, root_collection=GridStore.default_root_collection) def self.mv(db, src, dest, root_collection=GridStore.default_root_collection)
warn DEPRECATION_WARNING
db.collection("#{root_collection}.files").update({ :filename => src }, { '$set' => { :filename => dest } }) db.collection("#{root_collection}.files").update({ :filename => src }, { '$set' => { :filename => dest } })
end end
@ -210,7 +223,9 @@ module GridFS
# #
# @option options [String] :content_type ('text/plain') Set the content type stored as the # @option options [String] :content_type ('text/plain') Set the content type stored as the
# file's metadata. See also GridStore#content_type=. # file's metadata. See also GridStore#content_type=.
# @deprecated
def initialize(db, name, mode='r', options={}) def initialize(db, name, mode='r', options={})
warn DEPRECATION_WARNING
@db, @filename, @mode = db, name, mode @db, @filename, @mode = db, name, mode
@root = options[:root] || GridStore.default_root_collection @root = options[:root] || GridStore.default_root_collection