Module: CropImageRiffpad::ClassMethods

Defined in:
lib/cropimage_riffpad/crop_image_model.rb

Instance Method Summary collapse

Instance Method Details

#awesome_crop(attachment_name) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cropimage_riffpad/crop_image_model.rb', line 3

def awesome_crop(attachment_name)
  # todo - define instance methods
  attr_accessor :crop_x, :crop_y, :crop_w, :crop_h
  after_update "preprocess_#{attachment_name}", :if => :cropping?
  attr_accessible  :crop_x, :crop_y, :crop_w, :crop_h
  self.class_eval do 
    
    def cropping?
      !crop_x.blank? && !crop_y.blank? && !crop_w.blank? && !crop_h.blank?
    end
    
     define_method "#{attachment_name}_geometry" do |style=:original|
       @geometry ||= {}
       @geometry[style] ||= Paperclip::Geometry.from_file(self.send(attachment_name).path(style))
    end
      
    private

    define_method "preprocess_#{attachment_name}" do
      self.send(attachment_name).reprocess!
    end
    
  end
end