Sha256: 10519eab41f8ea237f0119d7e55c68e41468060aeac5e88a4e410f580c67a5d5
Contents?: true
Size: 846 Bytes
Versions: 1
Compression:
Stored size: 846 Bytes
Contents
module MongoMapperExt class File < GridFS::GridStore attr_reader :id, :attributes def initialize(owner, attrs = {}) @owner = owner @id = attrs.delete("_id") class_eval do attrs.each do |k,v| define_method(k) do v end end end super(@owner.class.database, attrs["filename"], "r", :root => @owner.collection.name) end def [](name) @attributes[name.to_s] end def self.fetch(owner, filename) db = owner.class.database criteria, options = MongoMapper::FinderOptions.new(owner.class, :filename => filename, :metadata => {:_id => owner.id}, :limit => 1).to_a obj = db.collection("#{owner.collection.name}.files").find(criteria, options).next_object if obj self.new(owner, obj) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
mongomapper_ext-0.0.4 | lib/mongomapper_ext/file.rb |