Class: Paperdragon::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/paperdragon/task.rb

Overview

Gives a simple API for processing multiple versions of a single attachment.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attachment, upload = nil) {|_self| ... } ⇒ Task

Returns a new instance of Task.

Yields:

  • (_self)

Yield Parameters:



4
5
6
7
8
9
10
# File 'lib/paperdragon/task.rb', line 4

def initialize(attachment, upload=nil)
  @attachment = attachment
  @upload     = upload
  @metadata   = attachment..dup # DISCUSS: keep this dependency?

  yield self if block_given?
end

Instance Attribute Details

#metadataObject (readonly)

Returns the value of attribute metadata.



12
13
14
# File 'lib/paperdragon/task.rb', line 12

def 
  @metadata
end

Instance Method Details

#metadata_hashObject

semi-private, might be removed.



13
14
15
# File 'lib/paperdragon/task.rb', line 13

def  # semi-private, might be removed.
  .to_hash
end

#process!(style, &block) ⇒ Object

process!(style, [*args,] &block) :

version = CoverGirl::Photo.new(@model, style, *args)
 = version.process!(upload, &block)
merge! {style => }


21
22
23
24
25
26
# File 'lib/paperdragon/task.rb', line 21

def process!(style, &block)
  version = file(style, upload)
  new_uid = new_uid_for(style, version) # new uid when overwriting existing attachment.

  @metadata.merge!(style => version.process!(upload, new_uid, &block))
end

#rename!(style, fingerprint, &block) ⇒ Object



38
39
40
41
42
43
# File 'lib/paperdragon/task.rb', line 38

def rename!(style, fingerprint, &block)
  version = file(style)
  new_uid = @attachment.rebuild_uid(version, fingerprint)

  @metadata.merge!(style => version.rename!(new_uid, &block))
end

#reprocess!(style, fingerprint = nil, original = nil, &block) ⇒ Object

fingerprint optional => filename is gonna remain the same original nil => use [:original]



30
31
32
33
34
35
36
# File 'lib/paperdragon/task.rb', line 30

def reprocess!(style, fingerprint=nil, original=nil, &block)
  @original ||= file(:original) # this is cached per task instance.
  version     = file(style)
  new_uid     = @attachment.rebuild_uid(version, fingerprint)

  @metadata.merge!(style => version.reprocess!(new_uid, @original, &block))
end