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
100 101 102 103 104 105 106 107 108 |
# File 'lib/papercrop/model_extension.rb', line 100 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
76 77 78 79 80 81 |
# File 'lib/papercrop/model_extension.rb', line 76 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
89 90 91 92 93 94 95 96 |
# File 'lib/papercrop/model_extension.rb', line 89 def image_geometry(, style = :original) @geometry ||= {} @geometry[] ||= {} path = (self.send().[:storage] == :filesystem) ? self.send().path(style) : self.send().url(style) @geometry[][style] ||= Paperclip::Geometry.from_file(path) end |
#reset_crop_attributes_of(attachment_name) ⇒ Object
Sets all cropping attributes to nil
113 114 115 116 117 |
# File 'lib/papercrop/model_extension.rb', line 113 def reset_crop_attributes_of() [:crop_x, :crop_y, :crop_w, :crop_h].each do |a| self.send :"#{}_#{a}=", nil end end |