Module: Papercrop::ActiveRecordExtension::InstanceMethods

Defined in:
lib/papercrop/active_record_extension.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

Uses method missing to reprocess the attachment callback



69
70
71
72
73
74
75
76
77
# File 'lib/papercrop/active_record_extension.rb', line 69

def method_missing(method, *args)
  if method.to_s =~ /(reprocess_to_crop_)(\S{1,})(_attachment)/
    reprocess_cropped_attachment(
      method.to_s.scan(/(reprocess_to_crop_)(\S{1,})(_attachment)/).flatten.second.to_sym
    )
  else
    super
  end
end

Instance Method Details

#cropping?(attachment_name) ⇒ Boolean

Asks if the attachment received a crop process

Returns:

  • (Boolean)


49
50
51
52
53
54
# File 'lib/papercrop/active_record_extension.rb', line 49

def cropping?(attachment_name)
  !self.send(:"#{attachment_name}_crop_x").blank? &&
  !self.send(:"#{attachment_name}_crop_y").blank? &&
  !self.send(:"#{attachment_name}_crop_w").blank? &&
  !self.send(:"#{attachment_name}_crop_h").blank?
end

#image_geometry(attachment_name, style = :original) ⇒ Object

Returns a Paperclip::Geometry object from a named attachment

Parameters:

  • attachment_name (Symbol)
  • style (Symbol) (defaults to: :original)

    attachment style, :original by default

Returns:

  • Paperclip::Geometry



62
63
64
65
# File 'lib/papercrop/active_record_extension.rb', line 62

def image_geometry(attachment_name, style = :original)
  @geometry        ||= {}
  @geometry[style] ||= Paperclip::Geometry.from_file(self.send(attachment_name).path(style))
end