Module: Attached::InstanceMethods

Defined in:
lib/attached.rb

Instance Method Summary collapse

Instance Method Details

#attachment_for(name) ⇒ Object

Create or access attachment.

Usage:

attachment_for :avatar


247
248
249
250
# File 'lib/attached.rb', line 247

def attachment_for(name)
  @_attached_attachments ||= {}
  @_attached_attachments[name] ||= Attachment.new(name, self, self.class.attached_options[name])
end

#destroy_attachedObject

Log and destroy all attached (using specified storage).

Usage:

before_save :destroy_attached


274
275
276
277
278
279
280
# File 'lib/attached.rb', line 274

def destroy_attached
  logger.info "[attached] destroy attached"
  
  self.class.attached_options.each do |name, options|
    attachment_for(name).destroy
  end
end

#save_attachedObject

Log and save all attached (using specified storage).

Usage:

before_save :save_attached


259
260
261
262
263
264
265
# File 'lib/attached.rb', line 259

def save_attached
  logger.info "[attached] save attached"
  
  self.class.attached_options.each do |name, options| 
    attachment_for(name).save
  end
end