Module: Mongoid::Paperclip::ImageDimension::ClassMethods

Defined in:
lib/mongoid_paperclip_image_dimension.rb

Instance Method Summary collapse

Instance Method Details

#save_image_dimensions_on(*args) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mongoid_paperclip_image_dimension.rb', line 12

def save_image_dimensions_on(*args)
  args.flatten.each do |attachment_field|
    attachment_field = attachment_field.to_sym
    dimension_field_name = "#{attachment_field}_dimensions".to_sym
    perperclip_image_dimension_fields << attachment_field
    field dimension_field_name, :type => Hash

    class_eval <<-END
      def #{attachment_field}_dimension(style=:original)
        #{attachment_field}_dimensions[style.to_s].map(&:to_i)
      end

      def #{attachment_field}_dimension_str(style=:original)
        #{attachment_field}_dimension(style).join('x')
      end

      after_#{attachment_field}_post_process do
        save_dimensions_for(:"#{attachment_field}")
      end
    END

  end
end