Module: Grip

Defined in:
lib/grip.rb

Overview

open : db, name, mode, options (:root, :metadata, :content_type) read : db, name, length, offset unlink : db, names list : db, root collection

GridStore.open(database, ‘filename’, ‘w’) { |f|

f.puts "Hello, world!"

}

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



21
22
23
# File 'lib/grip.rb', line 21

def self.included(base)
  base.extend Grip::ClassMethods
end

Instance Method Details

#destroy_attached_filesObject



69
70
71
72
73
# File 'lib/grip.rb', line 69

def destroy_attached_files
  self.class.attachment_definitions.each do |name, attachment|
    GridFS::GridStore.unlink(self.class.database, self["#{name}_path"])
  end
end

#save_attachmentsObject



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/grip.rb', line 57

def save_attachments
  self.class.attachment_definitions.each do |attachment|
    name, file = attachment
    
    if (file.is_a?(File) || file.is_a?(Tempfile))
      GridFS::GridStore.open(self.class.database, self["#{name}_path"], 'w', :content_type => self["#{name}_content_type"]) do |f|
        f.write(file.read)
      end
    end
  end
end