Module: AttachmentSaver::DataStores::InColumn
- Defined in:
- lib/datastores/in_column.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#delete_attachment ⇒ Object
delete_attachment is used when the record is deleted, so we don’t need to do anything.
- #in_storage? ⇒ Boolean
-
#reprocess! ⇒ Object
there is no public_path, since you need to make a controller to pull the blob from the database.
- #save_attachment ⇒ Object
- #save_temporary_and_process_attachment ⇒ Object
- #tidy_attachment ⇒ Object
Class Method Details
.included(base) ⇒ Object
8 9 10 11 |
# File 'lib/datastores/in_column.rb', line 8 def self.included(base) base.[:column_name] ||= 'data' base.[:temp_directory] ||= Dir.tmpdir end |
Instance Method Details
#delete_attachment ⇒ Object
delete_attachment is used when the record is deleted, so we don’t need to do anything
24 |
# File 'lib/datastores/in_column.rb', line 24 def ; end |
#in_storage? ⇒ Boolean
26 27 28 |
# File 'lib/datastores/in_column.rb', line 26 def in_storage? !send(self.class.[:column_name]).nil? end |
#reprocess! ⇒ Object
there is no public_path, since you need to make a controller to pull the blob from the database
32 33 34 35 36 |
# File 'lib/datastores/in_column.rb', line 32 def reprocess! raise "this attachment already has a file open to process" unless uploaded_file.nil? save! end |
#save_attachment ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/datastores/in_column.rb', line 13 def return unless @save_upload # this method is called every time the model is saved, not just when a new file has been uploaded send("#{self.class.[:column_name]}=", uploaded_data) if @save_upload = nil end |
#save_temporary_and_process_attachment ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/datastores/in_column.rb', line 38 def FileUtils.mkdir_p(self.class.[:temp_directory]) Tempfile.open("asctemp", self.class.[:temp_directory]) do |temp| temp.binmode temp.write(send(self.class.[:column_name])) temp.flush (temp.path) end end |
#tidy_attachment ⇒ Object
23 |
# File 'lib/datastores/in_column.rb', line 23 def ; end |