Class: Paperclip::Attachment

Inherits:
Object
  • Object
show all
Defined in:
lib/simple_crop/paperclip_patches/attachment.rb

Instance Method Summary collapse

Instance Method Details

#post_process(*style_args) ⇒ Object

:nodoc:



21
22
23
24
25
26
27
28
# File 'lib/simple_crop/paperclip_patches/attachment.rb', line 21

def post_process(*style_args) #:nodoc:
  return if @queued_for_write[:original].nil?
  instance.run_paperclip_callbacks(:post_process) do
    instance.run_paperclip_callbacks(:"#{name}_post_process") do
      post_process_styles(*style_args)
    end
  end
end

#post_process_styles(*style_args) ⇒ Object

:nodoc:



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/simple_crop/paperclip_patches/attachment.rb', line 30

def post_process_styles(*style_args) #:nodoc:
  styles.each do |name, style|
    begin
      if style_args.empty? || style_args.include?(name)  
        raise RuntimeError.new("Style #{name} has no processors defined.") if style.processors.blank?
        @queued_for_write[name] = style.processors.inject(@queued_for_write[:original]) do |file, processor|
          Paperclip.processor(processor).make(file, style.processor_options, self)
        end
      end
    rescue PaperclipError => e
      log("An error was received while processing: #{e.inspect}")
      (@errors[:processing] ||= []) << e.message if @whiny
    end
  end
end

#reprocess!(*style_args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/simple_crop/paperclip_patches/attachment.rb', line 3

def reprocess!(*style_args)
  new_original = Tempfile.new("paperclip-reprocess")
  new_original.binmode
  if old_original = to_file(:original)
    new_original.write( old_original.respond_to?(:get) ? old_original.get : old_original.read )
    new_original.rewind

    @queued_for_write = { :original => new_original }
    post_process(*style_args)

    old_original.close if old_original.respond_to?(:close)

    save
  else
    true
  end
end

#stylesObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/simple_crop/paperclip_patches/attachment.rb', line 46

def styles
  unless @normalized_styles
    @normalized_styles = {}
    (@styles.respond_to?(:call) ? @styles.call(self) : @styles).each do |name, args|
      @normalized_styles[name] = Paperclip::Style.new(name, args.dup, self)
    end
  end
  
  if @normalized_styles.blank? and instance.wants_simple_crop?
    temporary_simple_crop_style = {}
    temporary_simple_crop_style[:original] = Paperclip::Style.new(:original, "100000x100000>", self)
    return temporary_simple_crop_style
  end
  
  @normalized_styles
end