Module: Papercrop::ModelExtension::InstanceMethods
- Defined in:
- lib/papercrop/model_extension.rb
Instance Method Summary collapse
-
#cropping?(attachment_name) ⇒ Boolean
Asks if the attachment received a crop process.
-
#image_geometry(attachment_name, style = :original) ⇒ Paperclip::Geometry
Returns a Paperclip::Geometry object of a given attachment.
-
#method_missing(method, *args) ⇒ Object
Uses method missing to responding the model callback.
-
#reset_crop_attributes_of(attachment_name) ⇒ Object
Sets all cropping attributes to nil.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object
Uses method missing to responding the model callback
76 77 78 79 80 81 82 83 84 |
# File 'lib/papercrop/model_extension.rb', line 76 def method_missing(method, *args) if method.to_s =~ Papercrop::RegExp::CALLBACK ( method.to_s.scan(Papercrop::RegExp::CALLBACK).flatten.first.to_sym ) else super end end |
Instance Method Details
#cropping?(attachment_name) ⇒ Boolean
Asks if the attachment received a crop process
55 56 57 58 59 60 |
# File 'lib/papercrop/model_extension.rb', line 55 def cropping?() !self.send(:"#{}_crop_x").blank? && !self.send(:"#{}_crop_y").blank? && !self.send(:"#{}_crop_w").blank? && !self.send(:"#{}_crop_h").blank? end |
#image_geometry(attachment_name, style = :original) ⇒ Paperclip::Geometry
Returns a Paperclip::Geometry object of a given attachment
68 69 70 71 72 |
# File 'lib/papercrop/model_extension.rb', line 68 def image_geometry(, style = :original) @geometry ||= {} path = (self.send().[:storage] == :s3) ? self.send().url(style) : self.send().path(style) @geometry[style] ||= Paperclip::Geometry.from_file(path) end |
#reset_crop_attributes_of(attachment_name) ⇒ Object
Sets all cropping attributes to nil
89 90 91 92 93 |
# File 'lib/papercrop/model_extension.rb', line 89 def reset_crop_attributes_of() [:crop_x, :crop_y, :crop_w, :crop_h].each do |a| self.send :"#{}_#{a}=", nil end end |