Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/image/crop/is_image_cropped.rb

Class Method Summary collapse

Class Method Details

.is_image_cropped(*attr_names) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
# File 'lib/image/crop/is_image_cropped.rb', line 2

def self.is_image_cropped(*attr_names)
  before_save :process_cropped_images

  define_method 'process_cropped_images' do
    attr_names.each do |attr|
      if eval("self.#{attr}")
        image = Paperclip.io_adapters.for(eval("self.#{attr}"))
        image.original_filename = "cropped_file_#{Time.now.to_f.to_s.gsub('.','')}.#{self.picture_content_type.split('/').last}"
        eval("self.#{attr} = image")
      end
    end
  end
end