Module: Adrift::Integration::ActiveRecord

Includes:
Base
Defined in:
lib/adrift/integration/active_record.rb

Overview

Integrates Adrift with ActiveRecord.

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Base

#attachment_definitions

Class Method Details

.installObject

Integrates Adrift with ActiveRecord if it has been loaded.



19
20
21
22
23
# File 'lib/adrift/integration/active_record.rb', line 19

def self.install
  if defined?(::ActiveRecord::Base)
    ::ActiveRecord::Base.send(:extend, self)
  end
end

Instance Method Details

#attachmentObject

Does everything Base#attachment does, but it also registers the callbacks to save the attachments when the model is saved, and to destroy them, when it is destroyed.



12
13
14
15
16
# File 'lib/adrift/integration/active_record.rb', line 12

def attachment(*)
  super
  after_save     :save_attachments
  before_destroy :destroy_attachments
end