Class: Technoweenie::AttachmentFu::Backends::DbFileBackend
- Inherits:
-
BackendDelegator
- Object
- Delegator
- BackendDelegator
- Technoweenie::AttachmentFu::Backends::DbFileBackend
- Defined in:
- lib/technoweenie/attachment_fu/backends/db_file_backend.rb
Overview
Methods for DB backed attachments
Instance Attribute Summary
Attributes inherited from BackendDelegator
Class Method Summary collapse
Instance Method Summary collapse
-
#current_data ⇒ Object
Gets the current data from the database.
-
#destroy_file ⇒ Object
Destroys the file.
- #rename_file ⇒ Object
-
#save_to_storage ⇒ Object
Saves the data to the DbFile model.
Methods inherited from BackendDelegator
Constructor Details
This class inherits a constructor from Technoweenie::AttachmentFu::Backends::BackendDelegator
Class Method Details
.included_in_base(base) ⇒ Object
6 7 8 9 |
# File 'lib/technoweenie/attachment_fu/backends/db_file_backend.rb', line 6 def self.included_in_base(base) Object.const_set(:DbFile, Class.new(ActiveRecord::Base)) unless Object.const_defined?(:DbFile) base.belongs_to :db_file, :class_name => '::DbFile', :foreign_key => 'db_file_id' end |
Instance Method Details
#current_data ⇒ Object
Gets the current data from the database
14 15 16 |
# File 'lib/technoweenie/attachment_fu/backends/db_file_backend.rb', line 14 def current_data db_file && db_file.data end |
#destroy_file ⇒ Object
Destroys the file. Called in the after_destroy callback
19 20 21 |
# File 'lib/technoweenie/attachment_fu/backends/db_file_backend.rb', line 19 def destroy_file db_file.destroy if db_file end |
#rename_file ⇒ Object
11 |
# File 'lib/technoweenie/attachment_fu/backends/db_file_backend.rb', line 11 def rename_file ; end |
#save_to_storage ⇒ Object
Saves the data to the DbFile model
24 25 26 27 28 29 30 31 32 |
# File 'lib/technoweenie/attachment_fu/backends/db_file_backend.rb', line 24 def save_to_storage if (db_file || build_db_file).data = temp_data db_file.save! @obj.db_file_id = db_file.id @obj.class.where(id: @obj.id).update_all db_file_id: db_file.id end true end |