Sha256: e5a560ca8c920623f524967a86b248af21d1fee6b885c57089bf7cb4f01a2a67
Contents?: true
Size: 904 Bytes
Versions: 1
Compression:
Stored size: 904 Bytes
Contents
require 'active_record' require 'zlib' require 'wlog/domain/sys_config' module Wlog # Following the Active Record pattern # OO way of handling blobs of data, to be stored in memory or in db. class Attachment < ActiveRecord::Base before_save :compress_string after_initialize :uncompress_string belongs_to :attachable, polymorphic: true def to_s @strmaker = SysConfig.string_decorator str = '' str.concat(" [").concat(@strmaker.green(self.id)).concat("] ") str.concat(@strmaker.red(self.filename)).concat($/) str end private # TODO need to check if there is a better way to check for this def compress_string self.data = Zlib::Deflate.deflate self.data end def uncompress_string if self.data # did we just init something with previous data? yes; we can uncompress self.data = Zlib::Inflate.inflate self.data end end end end # module Wlog
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
wlog-1.2.2 | lib/wlog/domain/attachment.rb |