Sha256: 4ce614121b2d85f4330e3dab08b66d91f706f32ed5b7f7061ef2c27ba1bbd96e

Contents?: true

Size: 526 Bytes

Versions: 2

Compression:

Stored size: 526 Bytes

Contents

module Defile
  module ActiveRecord
    module Attachment
      include Defile::Attachment

      def attachment(name, cache: :cache, store: :store, raise_errors: false)
        super

        attachment = "#{name}_attachment"

        validate do
          errors = send(attachment).errors
          self.errors.add(name, *errors) unless errors.empty?
        end

        before_save do
          send(attachment).store!
        end
      end
    end
  end
end

::ActiveRecord::Base.extend(Defile::ActiveRecord::Attachment)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
defile-0.2.1 lib/defile/attachment/active_record.rb
defile-0.2.0 lib/defile/attachment/active_record.rb