factor out deps. formatting code.

This commit is contained in:
ahoward 2012-07-23 18:23:48 -06:00
parent bf57261f19
commit b024d8d707
4 changed files with 445 additions and 392 deletions

View File

@ -1,16 +1,61 @@
require "mongoid"
require "mime/types"
require "digest/md5"
require "cgi"
class GridFS
##
#
class GridFS
const_set :Version, '1.1.0'
class << GridFS
def version
"1.0.0"
const_get :Version
end
def dependencies
{
'mongoid' => [ 'mongoid' , ' >= 3.0.1' ] ,
'mime/types' => [ 'mime-types' , ' >= 1.19' ] ,
}
end
def libdir(*args, &block)
@libdir ||= File.expand_path(__FILE__).sub(/\.rb$/,'')
args.empty? ? @libdir : File.join(@libdir, *args)
ensure
if block
begin
$LOAD_PATH.unshift(@libdir)
block.call()
ensure
$LOAD_PATH.shift()
end
end
end
def load(*libs)
libs = libs.join(' ').scan(/[^\s+]+/)
libdir{ libs.each{|lib| Kernel.load(lib) } }
end
end
begin
require 'rubygems'
rescue LoadError
nil
end
if defined?(gem)
dependencies.each do |lib, dependency|
gem(*dependency)
require(lib)
end
end
require "digest/md5"
require "cgi"
end
##
#
class GridFS
class << GridFS
attr_accessor :namespace
attr_accessor :file_model
attr_accessor :chunk_model
@ -44,8 +89,8 @@ class GridFS
end
end
##
#
##
#
def GridFS.namespace_for(prefix)
prefix = prefix.to_s.downcase
const = "::GridFS::#{ prefix.to_s.camelize }"
@ -53,8 +98,8 @@ class GridFS
const_defined?(namespace) ? const_get(namespace) : build_namespace_for(namespace)
end
##
#
##
#
def GridFS.build_namespace_for(prefix)
prefix = prefix.to_s.downcase
const = prefix.camelize
@ -216,8 +261,8 @@ class GridFS
end
end
##
#
##
#
def GridFS.build_file_model_for(namespace)
prefix = namespace.name.split(/::/).last.downcase
file_model_name = "#{ namespace.name }::File"
@ -319,8 +364,8 @@ class GridFS
end
end
##
#
##
#
def GridFS.build_chunk_model_for(namespace)
prefix = namespace.name.split(/::/).last.downcase
file_model_name = "#{ namespace.name }::File"
@ -358,8 +403,8 @@ class GridFS
end
end
##
#
##
#
def GridFS.reading(arg, &block)
if arg.respond_to?(:read)
rewind(arg) do |io|
@ -412,8 +457,10 @@ class GridFS
basename = ::File.basename(pathname.to_s)
CGI.unescape(basename).gsub(%r/[^0-9a-zA-Z_@)(~.-]/, '_').gsub(%r/_+/,'_')
end
end
end
GridFs = GridFS
##
#
GridFs = GridFS
GridFS.init!
GridFS.init!

View File

@ -3,7 +3,7 @@
Gem::Specification::new do |spec|
spec.name = "mongoid-grid_fs"
spec.version = "1.0.0"
spec.version = "1.1.0"
spec.platform = Gem::Platform::RUBY
spec.summary = "mongoid-grid_fs"
spec.description = "a mongoid 3/moped compatible implementation of the grid_fs specification"
@ -26,6 +26,10 @@ Gem::Specification::new do |spec|
spec.test_files = nil
spec.add_dependency(*["mongoid", " >= 3.0.1"])
spec.add_dependency(*["mime-types", " >= 1.19"])
spec.extensions.push(*[])

Binary file not shown.

View File

@ -142,6 +142,8 @@ Testing GridFs do
protected
def object_id_re
%r| \w{#{ BSON::ObjectId.new.to_s.size }} |iomx
object_id = defined?(Moped) ? Moped::BSON::ObjectId.new : BSON::ObjectId.new
%r| \w{#{ object_id.to_s.size }} |iomx
end
end