Sha256: a560277f73e38b8658b6460b6aef4fe14fe63b01c649d6cffb6a083e44d4dbbc

Contents?: true

Size: 829 Bytes

Versions: 10

Compression:

Stored size: 829 Bytes

Contents

require './helper'

class StorageEx
  include MongoMapper::Document
  include MongoMapperExt::Storage

  file_key :default_file

  file_list :attachments
  file_key :an_attachment, :in => :attachments
end

default_file = StringIO.new("default file content")
custom_attachment = StringIO.new("custom attachment content")

attachment = File.open(__FILE__)

StorageEx.destroy_all

s = StorageEx.new

s.default_file = default_file
s.attachments.put("custom_attachment.txt", custom_attachment)
s.an_attachment = attachment

s.save


from_db = StorageEx.find(s.id)

puts "READ DEFAULT FILE"
puts from_db.default_file.read

puts "READ CUSTOM ATTACHMENT"
puts from_db.attachments.get("custom_attachment.txt").read

puts "READ NAMED ATTACHMENT"
puts from_db.an_attachment.read.inspect
puts "MIME TYPE: #{from_db.an_attachment.mime_type}"

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
mongomapper_ext-0.5.2 examples/storage.rb
mongomapper_ext-0.5.1 examples/storage.rb
mongomapper_ext-0.5.0 examples/storage.rb
mongomapper_ext-0.4.0 examples/storage.rb
mongomapper_ext-0.3.0 examples/storage.rb
mongomapper_ext-0.2.4 examples/storage.rb
mongomapper_ext-0.2.3 examples/storage.rb
mongomapper_ext-0.2.2 examples/storage.rb
mongomapper_ext-0.2.1 examples/storage.rb
mongomapper_ext-0.2.0 examples/storage.rb