Module: PaperCropper::ModelExtension::InstanceMethods

Defined in:
lib/paper_cropper/model_extension.rb

Overview

Instance methods #########################################################################

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 responding the model callback for reprocess the image



98
99
100
101
102
103
104
105
106
# File 'lib/paper_cropper/model_extension.rb', line 98

def method_missing(method, *args)
  if method.to_s =~ PaperCropper::RegExp::CALLBACK
    reprocess_cropped_attachment(
      method.to_s.scan(PaperCropper::RegExp::CALLBACK).flatten.first.to_sym
    )
  else
    super
  end
end

Instance Method Details

#attachment_changed?(attachment_name) ⇒ Boolean

Returns:

  • (Boolean)


83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/paper_cropper/model_extension.rb', line 83

def attachment_changed?(attachment_name)
  ["#{attachment_name}_name", "#{attachment_name}_content_type",
    "#{attachment_name}_file_size", "#{attachment_name}_updated_at",
    "#{attachment_name}_crop_x", "#{attachment_name}_crop_y",
    "#{attachment_name}_crop_width", "#{attachment_name}_crop_height",
    "#{attachment_name}_crop_ratio"
  ].any? { |attr|
    method= "#{attr}_changed?".to_sym
    if respond_to?(method)
      self.send(method)
    end
  }
end

#cropping?(attachment_name) ⇒ Boolean

Asks if the attachment received a crop process

Parameters:

  • attachment_name (Symbol)

Returns:

  • (Boolean)


76
77
78
79
80
81
# File 'lib/paper_cropper/model_extension.rb', line 76

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