Module: Adrift::Integration::Base::InstanceMethods

Defined in:
lib/adrift/integration/base.rb

Overview

Methods that handle the communication with the Attachments of a given model.

They are included in the model class by Base#attachment.

Instance Method Summary collapse

Instance Method Details

#attachmentsObject

Attachment objects that belongs to the model. It needs the model class to be able to respond to attachment_definitions with a Hash where the keys are the Attachment names.



14
15
16
# File 'lib/adrift/integration/base.rb', line 14

def attachments
  self.class.attachment_definitions.keys.map { |name| send(name) }
end

#destroy_attachmentsObject

Sends the message :destroy to the Attachment objects that belongs to the model.



32
33
34
# File 'lib/adrift/integration/base.rb', line 32

def destroy_attachments
  send_to_attachments(:destroy)
end

#save_attachmentsObject

Sends the message :save to the Attachment objects that belongs to the model.



26
27
28
# File 'lib/adrift/integration/base.rb', line 26

def save_attachments
  send_to_attachments(:save)
end

#send_to_attachments(message) ⇒ Object

Sends message to the Attachment objects that belongs to the model.



20
21
22
# File 'lib/adrift/integration/base.rb', line 20

def send_to_attachments(message)
  attachments.each { |attachment| attachment.send(message) }
end