class Attach::Processor

Public Class Methods

background(&block) click to toggle source
# File lib/attach/processor.rb, line 4
def self.background(&block)
  @background_block = block
end
background_block() click to toggle source
# File lib/attach/processor.rb, line 8
def self.background_block
  @background_block
end
new(attachment) click to toggle source
# File lib/attach/processor.rb, line 22
def initialize(attachment)
  @attachment = attachment
end
processor(model, attribute) click to toggle source
# 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) click to toggle source
# 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

Public Instance Methods

process() click to toggle source
# File lib/attach/processor.rb, line 26
def process
  call_processors(@attachment)
  @attachment.processed = true
  @attachment.save(:validate => false)
end
queue_or_process() click to toggle source
# 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

Private Instance Methods

call_processors(attachment) click to toggle source
# File lib/attach/processor.rb, line 42
def call_processors(attachment)
  if p = self.class.processor(attachment.owner_type, attachment.role)
    p.call(attachment)
  end
end