Module: DelayedPaperclip::Attachment

Defined in:
lib/delayed_paperclip/attachment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#job_is_processingObject

Returns the value of attribute job_is_processing.



3
4
5
# File 'lib/delayed_paperclip/attachment.rb', line 3

def job_is_processing
  @job_is_processing
end

Instance Method Details

#delay_processing?Boolean

if nil, returns whether it has delayed options if set, then it returns

Returns:

  • (Boolean)


20
21
22
23
24
25
26
# File 'lib/delayed_paperclip/attachment.rb', line 20

def delay_processing?
  if @post_processing_with_delay.nil?
    !!delayed_options
  else
    !@post_processing_with_delay
  end
end

#delayed_only_processObject



44
45
46
47
48
# File 'lib/delayed_paperclip/attachment.rb', line 44

def delayed_only_process
  only_process = delayed_options.fetch(:only_process, []).dup
  only_process = only_process.call(self) if only_process.respond_to?(:call)
  only_process.map(&:to_sym)
end

#delayed_optionsObject



5
6
7
# File 'lib/delayed_paperclip/attachment.rb', line 5

def delayed_options
  options[:delayed]
end

#post_processingObject

Attr accessor in Paperclip



10
11
12
# File 'lib/delayed_paperclip/attachment.rb', line 10

def post_processing
  !delay_processing? || split_processing?
end

#post_processing=(value) ⇒ Object



14
15
16
# File 'lib/delayed_paperclip/attachment.rb', line 14

def post_processing=(value)
  @post_processing_with_delay = value
end

#process_delayed!Object



50
51
52
53
54
55
56
# File 'lib/delayed_paperclip/attachment.rb', line 50

def process_delayed!
  self.job_is_processing = true
  self.post_processing = true
  reprocess!(*delayed_only_process)
  self.job_is_processing = false
  update_processing_column
end

#processing?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'lib/delayed_paperclip/attachment.rb', line 33

def processing?
  column_name = :"#{@name}_processing?"
  @instance.respond_to?(column_name) && @instance.send(column_name)
end

#processing_image_urlObject



58
59
60
61
62
# File 'lib/delayed_paperclip/attachment.rb', line 58

def processing_image_url
  processing_image_url = delayed_options[:processing_image_url]
  processing_image_url = processing_image_url.call(self) if processing_image_url.respond_to?(:call)
  processing_image_url
end

#processing_style?(style) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/delayed_paperclip/attachment.rb', line 38

def processing_style?(style)
  return false if !processing?

  !split_processing? || delayed_only_process.include?(style)
end

#reprocess_without_delay!(*style_args) ⇒ Object



74
75
76
77
# File 'lib/delayed_paperclip/attachment.rb', line 74

def reprocess_without_delay!(*style_args)
  @post_processing_with_delay = true
  reprocess!(*style_args)
end

#saveObject



64
65
66
67
68
69
70
71
72
# File 'lib/delayed_paperclip/attachment.rb', line 64

def save
  was_dirty = @dirty

  super.tap do
    if delay_processing? && was_dirty
      instance.prepare_enqueueing_for name
    end
  end
end

#split_processing?Boolean

Returns:

  • (Boolean)


28
29
30
31
# File 'lib/delayed_paperclip/attachment.rb', line 28

def split_processing?
  options[:only_process] && delayed_options &&
    options[:only_process] != delayed_only_process
end