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.

Each processing method will return the updated metadata hash. You still have to save that hash back to the model.

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:



7
8
9
10
11
12
13
# File 'lib/paperdragon/task.rb', line 7

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.



15
16
17
# File 'lib/paperdragon/task.rb', line 15

def 
  @metadata
end

Instance Method Details

#delete!(*styles) ⇒ Object



48
49
50
51
52
53
54
55
56
57
# File 'lib/paperdragon/task.rb', line 48

def delete!(*styles)
  styles = @attachment..keys if styles.size == 0

  styles.each do |style|
    file(style).delete!
    @metadata.delete(style)
  end

  @metadata
end

#metadata_hashObject

semi-private, might be removed.



16
17
18
# File 'lib/paperdragon/task.rb', line 16

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 => }


24
25
26
27
28
29
# File 'lib/paperdragon/task.rb', line 24

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



41
42
43
44
45
46
# File 'lib/paperdragon/task.rb', line 41

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]



33
34
35
36
37
38
39
# File 'lib/paperdragon/task.rb', line 33

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