Class: Attach::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/attach/processor.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attachment) ⇒ Processor

Returns a new instance of Processor.



22
23
24
# File 'lib/attach/processor.rb', line 22

def initialize(attachment)
  @attachment = attachment
end

Class Method Details

.background(&block) ⇒ Object



4
5
6
# File 'lib/attach/processor.rb', line 4

def self.background(&block)
  @background_block = block
end

.background_blockObject



8
9
10
# File 'lib/attach/processor.rb', line 8

def self.background_block
  @background_block
end

.processor(model, attribute) ⇒ Object



18
19
20
# File 'lib/attach/processor.rb', line 18

def self.processor(model, attribute)
  @processors && @processors[[model.to_s, attribute.to_s]]
end

.register(model, attribute, &block) ⇒ Object



12
13
14
15
16
# File 'lib/attach/processor.rb', line 12

def self.register(model, attribute, &block)
  @processors ||= {}
  @processors[[model.to_s, attribute.to_s]] ||= []
  @processors[[model.to_s, attribute.to_s]] = block
end

Instance Method Details

#processObject



26
27
28
29
30
# File 'lib/attach/processor.rb', line 26

def process
  call_processors(@attachment)
  @attachment.processed = true
  @attachment.save(:validate => false)
end

#queue_or_processObject



32
33
34
35
36
37
38
# File 'lib/attach/processor.rb', line 32

def queue_or_process
  if self.class.background_block
    self.class.background_block.call(@attachment)
  else
    process
  end
end