Module: Paperclip

Extended by:
Helpers, Logger, ProcessorHelpers
Defined in:
lib/paperclip.rb,
lib/paperclip/glue.rb,
lib/paperclip/style.rb,
lib/paperclip/logger.rb,
lib/paperclip/schema.rb,
lib/paperclip/errors.rb,
lib/paperclip/version.rb,
lib/paperclip/railtie.rb,
lib/paperclip/helpers.rb,
lib/paperclip/geometry.rb,
lib/paperclip/matchers.rb,
lib/paperclip/tempfile.rb,
lib/paperclip/thumbnail.rb,
lib/paperclip/callbacks.rb,
lib/paperclip/processor.rb,
lib/paperclip/validators.rb,
lib/paperclip/attachment.rb,
lib/paperclip/storage/s3.rb,
lib/paperclip/storage/fog.rb,
lib/paperclip/url_generator.rb,
lib/paperclip/interpolations.rb,
lib/paperclip/tempfile_factory.rb,
lib/paperclip/instance_methods.rb,
lib/paperclip/storage/filesystem.rb,
lib/paperclip/attachment_options.rb,
lib/paperclip/io_adapters/registry.rb,
lib/paperclip/content_type_detector.rb,
lib/paperclip/io_adapters/uri_adapter.rb,
lib/paperclip/io_adapters/nil_adapter.rb,
lib/paperclip/geometry_parser_factory.rb,
lib/paperclip/io_adapters/file_adapter.rb,
lib/paperclip/missing_attachment_styles.rb,
lib/paperclip/geometry_detector_factory.rb,
lib/paperclip/interpolations/plural_cache.rb,
lib/paperclip/io_adapters/stringio_adapter.rb,
lib/paperclip/io_adapters/abstract_adapter.rb,
lib/paperclip/io_adapters/identity_adapter.rb,
lib/paperclip/io_adapters/attachment_adapter.rb,
lib/paperclip/io_adapters/uploaded_file_adapter.rb,
lib/paperclip/file_command_content_type_detector.rb,
lib/paperclip/matchers/have_attached_file_matcher.rb,
lib/paperclip/validators/attachment_size_validator.rb,
lib/paperclip/validators/attachment_presence_validator.rb,
lib/paperclip/matchers/validate_attachment_size_matcher.rb,
lib/paperclip/validators/attachment_content_type_validator.rb,
lib/paperclip/matchers/validate_attachment_presence_matcher.rb,
lib/paperclip/matchers/validate_attachment_content_type_matcher.rb

Overview

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

Defined Under Namespace

Modules: Callbacks, ClassMethods, Errors, Glue, Helpers, InstanceMethods, Interpolations, Logger, ProcessorHelpers, Schema, Shoulda, Storage, TempfileEncoding, Validators Classes: AbstractAdapter, AdapterRegistry, Attachment, AttachmentAdapter, AttachmentOptions, ContentTypeDetector, Error, FileAdapter, FileCommandContentTypeDetector, Geometry, GeometryDetector, GeometryParser, IdentityAdapter, NilAdapter, Processor, Railtie, StringioAdapter, Style, Tempfile, TempfileFactory, Thumbnail, UploadedFileAdapter, UriAdapter, UrlGenerator

Constant Summary

VERSION =
"3.4.2"

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Methods included from ProcessorHelpers

clear_processors!, load_processor, processor, register_processor

Methods included from Logger

log, logger, logger=, logging?

Methods included from Helpers

class_for, configure, each_instance_with_attachment, interpolates, reset_duplicate_clash_check!, run

Class Attribute Details

+ (Object) classes_with_attachments

Returns the value of attribute classes_with_attachments



5
6
7
# File 'lib/paperclip/missing_attachment_styles.rb', line 5

def classes_with_attachments
  @classes_with_attachments
end

+ (Object) registered_attachments_styles_path



7
8
9
# 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

Class Method Details

+ (Object) current_attachments_styles

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]},
  }
}


37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/paperclip/missing_attachment_styles.rb', line 37

def self.current_attachments_styles
  Hash.new.tap do |current_styles|
    Paperclip.classes_with_attachments.each do |klass_name|
      klass = Paperclip.class_for(klass_name)
      klass.attachment_definitions.each do |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
end

+ (Object) get_registered_attachments_styles

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



15
16
17
18
19
# File 'lib/paperclip/missing_attachment_styles.rb', line 15

def self.get_registered_attachments_styles
  YAML.load_file(Paperclip.registered_attachments_styles_path)
rescue Errno::ENOENT
  nil
end

+ (Object) io_adapters



91
92
93
# File 'lib/paperclip.rb', line 91

def self.io_adapters
  @io_adapters ||= Paperclip::AdapterRegistry.new
end

+ (Object) io_adapters=(new_registry)



87
88
89
# File 'lib/paperclip.rb', line 87

def self.io_adapters=(new_registry)
  @io_adapters = new_registry
end

+ (Object) missing_attachments_styles

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

{
  :User => {:avatar => [:big]},
  :Book => {
    :cover => [:croppable]},
  }
}


64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/paperclip/missing_attachment_styles.rb', line 64

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

+ (Object) options

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.



76
77
78
79
80
81
82
83
84
85
# File 'lib/paperclip.rb', line 76

def self.options
  @options ||= {
    :whiny             => true,
    :image_magick_path => nil,
    :command_path      => nil,
    :log               => true,
    :log_command       => true,
    :swallow_stderr    => true
  }
end

+ (Object) save_current_attachments_styles!



22
23
24
25
26
# File 'lib/paperclip/missing_attachment_styles.rb', line 22

def self.save_current_attachments_styles!
  File.open(Paperclip.registered_attachments_styles_path, 'w') do |f|
    YAML.dump(current_attachments_styles, f)
  end
end