Module: ActiveMetadata::Persistence::ActiveRecord::Attachment::InstanceMethods

Defined in:
lib/active_metadata/persistence/active_record/attachment.rb

Instance Method Summary collapse

Instance Method Details

#attachments_for(field) ⇒ Object



15
16
17
18
19
# File 'lib/active_metadata/persistence/active_record/attachment.rb', line 15

def attachments_for(field)
  Rails.cache.fetch(attachments_cache_key(field), :expires_in => ActiveMetadata::CONFIG['cache_expires_in'].minutes) do
    fetch_attachments_for field   
  end  
end

#delete_attachment_for(field, id) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/active_metadata/persistence/active_record/attachment.rb', line 21

def delete_attachment_for(field,id)
  a = Attachment.find(id)
  filename = a.attach.original_filename
  a.destroy      
  reload_attachments_cache_for field 
  self.send(:send_notification, field, filename, "", :attachment_message)
end

#has_attachments_for(field) ⇒ Object



41
42
43
# File 'lib/active_metadata/persistence/active_record/attachment.rb', line 41

def has_attachments_for field
  attachments_for(field).size == 0 ? false : true
end

#save_attachment_for(field, file) ⇒ Object



9
10
11
12
13
# File 'lib/active_metadata/persistence/active_record/attachment.rb', line 9

def save_attachment_for(field, file)      
  attachment = Attachment.create! :document_class => , :document_id => , :label => field, :attach => file, :created_by => current_user_id
  reload_attachments_cache_for field 
  self.send(:send_notification, field, "", attachment.attach.original_filename, :attachment_message, current_user_id)
end

#update_attachment_for(field, id, newfile) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/active_metadata/persistence/active_record/attachment.rb', line 29

def update_attachment_for(field, id, newfile)
  a = Attachment.find(id)
  old_filename = a.attach.original_filename
  a.attach = newfile
  a.updated_by = current_user_id
  a.save                                            
  new_filename = a.attach.original_filename

  reload_attachments_cache_for field       
  self.send(:send_notification, field, old_filename, new_filename, :attachment_message, current_user_id)
end