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


243
244
245
246
# File 'lib/attached.rb', line 243

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


270
271
272
273
274
275
276
# File 'lib/attached.rb', line 270

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


255
256
257
258
259
260
261
# File 'lib/attached.rb', line 255

def save_attached
  logger.info "[attached] save attached"

  self.class.attached_options.each do |name, options|
    attachment_for(name).save
  end
end