Class: Paperclip::Attachment
- Inherits:
-
Object
- Object
- Paperclip::Attachment
- Defined in:
- lib/paperclip-meta.rb
Instance Method Summary collapse
- #image_size(style = default_style) ⇒ Object
- #original_post_process_styles ⇒ Object
- #original_save ⇒ Object
-
#post_process_styles ⇒ Object
If model has #name_meta column we getting sizes of processed thumbnails and saving it to #name_meta column.
-
#save ⇒ Object
If attachment deleted - destroy meta data.
Instance Method Details
#image_size(style = default_style) ⇒ Object
52 53 54 |
# File 'lib/paperclip-meta.rb', line 52 def image_size(style = default_style) "#{width(style)}x#{height(style)}" end |
#original_post_process_styles ⇒ Object
3 |
# File 'lib/paperclip-meta.rb', line 3 alias :original_post_process_styles :post_process_styles |
#original_save ⇒ Object
4 |
# File 'lib/paperclip-meta.rb', line 4 alias :original_save :save |
#post_process_styles ⇒ Object
If model has #name_meta column we getting sizes of processed thumbnails and saving it to #name_meta column.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/paperclip-meta.rb', line 16 def post_process_styles original_post_process_styles if instance.respond_to?(:"#{name}_meta=") = {} @queued_for_write.each do |style, file| if File.extname(file) == 'swf' begin header = SwfFile::FlashFile.header file [style] = {:width => header.width.to_i, :height => header.height.to_i, :size => File.size(file) } rescue SwfFileHeaderError => e [style] = {} end else begin geo = Geometry.from_file file [style] = {:width => geo.width.to_i, :height => geo.height.to_i, :size => File.size(file) } rescue NotIdentifiedByImageMagickError => e [style] = {} end end end instance_write(:meta, ActiveSupport::Base64.encode64(Marshal.dump())) end end |
#save ⇒ Object
If attachment deleted - destroy meta data
7 8 9 10 11 12 |
# File 'lib/paperclip-meta.rb', line 7 def save if (not @queued_for_delete.empty?) and @queued_for_write.empty? instance_write(:meta, ActiveSupport::Base64.encode64(Marshal.dump({}))) if instance.respond_to?(:"#{name}_meta=") end original_save end |