Class: Paperdragon::Task
- Inherits:
-
Object
- Object
- Paperdragon::Task
- 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
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
- #delete!(*styles) ⇒ Object
-
#initialize(attachment, upload = nil) {|_self| ... } ⇒ Task
constructor
A new instance of Task.
-
#metadata_hash ⇒ Object
semi-private, might be removed.
-
#process!(style, &block) ⇒ Object
process!(style, [*args,] &block) : version = CoverGirl::Photo.new(@model, style, *args) metadata = version.process!(upload, &block) merge! => metadata.
- #rename!(style, fingerprint, &block) ⇒ Object
-
#reprocess!(style, fingerprint = nil, original = nil, &block) ⇒ Object
fingerprint optional => filename is gonna remain the same original nil => use [:original].
Constructor Details
#initialize(attachment, upload = nil) {|_self| ... } ⇒ Task
Returns a new instance of Task.
7 8 9 10 11 12 13 |
# File 'lib/paperdragon/task.rb', line 7 def initialize(, upload=nil) @attachment = @upload = upload @metadata = ..dup # DISCUSS: keep this dependency? yield self if block_given? end |
Instance Attribute Details
#metadata ⇒ Object (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_hash ⇒ Object
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 |