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.
Instance Attribute Summary collapse
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Instance Method Summary collapse
-
#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.
4 5 6 7 8 9 10 |
# File 'lib/paperdragon/task.rb', line 4 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.
12 13 14 |
# File 'lib/paperdragon/task.rb', line 12 def @metadata end |
Instance Method Details
#metadata_hash ⇒ Object
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 |