Sha256: b0d009dd4a1655a3b8afff9373404ba41a0b5b50f30f378a2681ea7407731659
Contents?: true
Size: 1.4 KB
Versions: 4
Compression:
Stored size: 1.4 KB
Contents
module Joint module InstanceMethods def grid @grid ||= Mongo::Grid.new(database) end private def assigned_attachments @assigned_attachments ||= {} end def nil_attachments @nil_attachments ||= Set.new end # IO must respond to read and rewind def save_attachments assigned_attachments.each_pair do |name, io| next unless io.respond_to?(:read) io.rewind if io.respond_to?(:rewind) grid.delete(send(name).id) grid.put(io.read, { :_id => send(name).id, :filename => send(name).name, :content_type => send(name).type, }) end assigned_attachments.clear end def destroy_nil_attachments # currently MM does not send sets to instance as well nil_attachments.each do |name| grid.delete(send(name).id) send(:"#{name}_id=", nil) send(:"#{name}_size=", nil) send(:"#{name}_type=", nil) send(:"#{name}_name=", nil) set({ :"#{name}_id" => nil, :"#{name}_size" => nil, :"#{name}_type" => nil, :"#{name}_name" => nil, }) end nil_attachments.clear end def destroy_all_attachments self.class.attachment_names.map { |name| grid.delete(send(name).id) } end end end
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
joint-0.5.5 | lib/joint/instance_methods.rb |
joint-0.5.4 | lib/joint/instance_methods.rb |
joint-0.5.3 | lib/joint/instance_methods.rb |
joint-0.5.2 | lib/joint/instance_methods.rb |