module Paperclip::Dimension::ClassMethods

Public Instance Methods

has_attached_file(name, options={}) click to toggle source

override has_attached_file to: 1). save dimensions on post process 2). create dimension accessors

Calls superclass method
# File lib/paperclip-dimension.rb, line 13
      def has_attached_file name, options={}
        super

        class_eval <<-END
          # for ActiveRecord
          serialize :#{name}_dimensions, Hash if respond_to?(:serialize)

          def #{name}_dimension(style=:original)
            self.#{name}_dimensions[style.to_s]
          end

          def #{name}_dimension_str(style=:original)
             dim = #{name}_dimension(style.to_s)
             dim ? dim.join('x') : nil
          end
        END

        send "after_#{name}_post_process", lambda { save_dimensions_for(name) }
      end