module Paperclip

The base module that gets included in ActiveRecord::Base. See the documentation for Paperclip::ClassMethods for more useful information.

Constants

REQUIRED_VALIDATORS
VERSION

Attributes

registered_attachments_styles_path[W]

Public Class Methods

io_adapters() click to toggle source
# File lib/paperclip.rb, line 109
def self.io_adapters
  @io_adapters ||= Paperclip::AdapterRegistry.new
end
io_adapters=(new_registry) click to toggle source
# File lib/paperclip.rb, line 105
def self.io_adapters=(new_registry)
  @io_adapters = new_registry
end
missing_attachments_styles() click to toggle source

Returns hash with styles missing from recent run of rake paperclip:refresh:missing_styles

{
  :User => {:avatar => [:big]},
  :Book => {
    :cover => [:croppable]},
  }
}
# File lib/paperclip/missing_attachment_styles.rb, line 59
def self.missing_attachments_styles
  current_styles = current_attachments_styles
  registered_styles = get_registered_attachments_styles

  Hash.new.tap do |missing_styles|
    current_styles.each do |klass, attachment_definitions|
      attachment_definitions.each do |attachment_name, styles|
        registered = registered_styles[klass][attachment_name] || [] rescue []
        missed = styles - registered
        if missed.present?
          klass_sym = klass.to_s.to_sym
          missing_styles[klass_sym] ||= Hash.new
          missing_styles[klass_sym][attachment_name.to_sym] ||= Array.new
          missing_styles[klass_sym][attachment_name.to_sym].concat(missed.to_a)
          missing_styles[klass_sym][attachment_name.to_sym].map!(&:to_s).sort!.map!(&:to_sym).uniq!
        end
      end
    end
  end
end
options() click to toggle source

Provides configurability to Paperclip. The options available are:

  • whiny: Will raise an error if Paperclip cannot process thumbnails of an uploaded image. Defaults to true.

  • log: Logs progress to the Rails log. Uses ActiveRecord's logger, so honors log levels, etc. Defaults to true.

  • command_path: Defines the path at which to find the command line programs if they are not visible to Rails the system's search path. Defaults to nil, which uses the first executable found in the user's search path.

  • use_exif_orientation: Whether to inspect EXIF data to determine an image's orientation. Defaults to true.

# File lib/paperclip.rb, line 91
def self.options
  @options ||= {
    command_path: nil,
    content_type_mappings: {},
    log: true,
    log_command: true,
    read_timeout: nil,
    swallow_stderr: true,
    use_exif_orientation: true,
    whiny: true,
    is_windows: Gem.win_platform?
  }
end
registered_attachments_styles_path() click to toggle source
# File lib/paperclip/missing_attachment_styles.rb, line 7
def registered_attachments_styles_path
  @registered_attachments_styles_path ||= Rails.root.join('public/system/paperclip_attachments.yml').to_s
end
save_current_attachments_styles!() click to toggle source
# File lib/paperclip/missing_attachment_styles.rb, line 20
def self.save_current_attachments_styles!
  File.open(Paperclip.registered_attachments_styles_path, 'w') do |f|
    YAML.dump(current_attachments_styles, f)
  end
end

Private Class Methods

current_attachments_styles() click to toggle source

Returns hash with styles for all classes using Paperclip. Unfortunately current version does not work with lambda styles:(

{
  :User => {:avatar => [:small, :big]},
  :Book => {
    :cover => [:thumb, :croppable]},
    :sample => [:thumb, :big]},
  }
}
# File lib/paperclip/missing_attachment_styles.rb, line 35
def self.current_attachments_styles
  Hash.new.tap do |current_styles|
    Paperclip::AttachmentRegistry.each_definition do |klass, attachment_name, attachment_attributes|
      # TODO: is it even possible to take into account Procs?
      next if attachment_attributes[:styles].kind_of?(Proc)
      attachment_attributes[:styles].try(:keys).try(:each) do |style_name|
        klass_sym = klass.to_s.to_sym
        current_styles[klass_sym] ||= Hash.new
        current_styles[klass_sym][attachment_name.to_sym] ||= Array.new
        current_styles[klass_sym][attachment_name.to_sym] << style_name.to_sym
        current_styles[klass_sym][attachment_name.to_sym].map!(&:to_s).sort!.map!(&:to_sym).uniq!
      end
    end
  end
end
get_registered_attachments_styles() click to toggle source

Get list of styles saved on previous deploy (running rake paperclip:refresh:missing_styles)

# File lib/paperclip/missing_attachment_styles.rb, line 13
def self.get_registered_attachments_styles
  YAML.load_file(Paperclip.registered_attachments_styles_path)
rescue Errno::ENOENT
  nil
end