Sha256: c55a7158fd4b045e13797b21b0ee35636253655524fc15060a10f0268fa04557

Contents?: true

Size: 657 Bytes

Versions: 1

Compression:

Stored size: 657 Bytes

Contents

require 'tori'

module Tori
  module ActiveRecord
    include Define

    # Filename hash usgin `id` attribute by default.
    # And you can change this attribute, But it's should be record unique.
    #
    # @example:
    # class Photo < ActiveRecord::Base
    #   tori :image
    # end
    def tori(name)
      super

      after_save do
        file = __send__ name
        Tori.config.backend.copy(file.from.path, file.to_s) if file.from && file.copy?
      end

      after_destroy do
        file = __send__ name
        Tori.config.backend.delete(file.to_s) if file.exist?
      end
    end
  end
end
::ActiveRecord::Base.extend(Tori::ActiveRecord)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tori-0.0.3 lib/tori/rails.rb