Class: Versions::SharedAttachment
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Versions::SharedAttachment
- Defined in:
- lib/versions/shared_attachment.rb
Instance Method Summary collapse
Instance Method Details
#file ⇒ Object
21 22 23 |
# File 'lib/versions/shared_attachment.rb', line 21 def file File.new(filepath) end |
#file=(file) ⇒ Object
16 17 18 19 |
# File 'lib/versions/shared_attachment.rb', line 16 def file=(file) @file = file self[:filename] = get_filename(file) end |
#filepath ⇒ Object
25 26 27 28 29 |
# File 'lib/versions/shared_attachment.rb', line 25 def filepath @filepath ||= begin digest = ::Digest::SHA1.hexdigest(self[:id].to_s) "#{digest[0..0]}/#{digest[1..1]}/#{filename}" end end |
#unlink(model) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/versions/shared_attachment.rb', line 9 def unlink(model) link_count = model.class.count(:conditions => ["attachment_id = ? AND id != ?", self.id, model.id]) if link_count == 0 destroy end end |