Permalink
Browse files

add AttachmentFu::Tasks#prepend

  • Loading branch information...
1 parent c011636 commit 45ade5b1f2270090a8a1ed5464bc0c15e647780d @technoweenie committed Dec 5, 2008
Showing with 12 additions and 4 deletions.
  1. +6 −1 lib/attachment_fu/tasks.rb
  2. +6 −3 spec/tasks_spec.rb
View
7 lib/attachment_fu/tasks.rb
@@ -133,7 +133,12 @@ def copy_for(klass, &block)
def task(key, options = {})
@stack << [load(key, options), options]
end
-
+
+ # Adds a new task to the top of this Tasks instance.
+ def prepend(key, options = {})
+ @stack.unshift([load(key, options), options])
+ end
+
# Loads a new task to this Tasks instance, but does not put it
# in the stack to be called during processing.
def load(key, options = {})
View
9 spec/tasks_spec.rb
@@ -5,7 +5,8 @@ module AttachmentFu
before :all do
Tasks.all.update \
:foo => FlakyTask,
- :bar => lambda { |a, o| a.filename = "bar-#{o[:a]}-#{a.filename}" }
+ :bar => lambda { |a, o| a.filename = "bar-#{o[:a]}-#{a.filename}" },
+ :baz => lambda { |a, o| }
@tasks = Tasks.new self do
set_pixel_adapter :core_image
task :foo, :a => 1
@@ -28,12 +29,14 @@ module AttachmentFu
t = Tasks.new self do
load :foo
task :bar
+ prepend :baz
end
t[:foo].should be_instance_of(FlakyTask)
t[:bar].should be_instance_of(Proc)
- t.size.should == 1
- t[0].should == [t[:bar], {}]
+ t.size.should == 2
+ t[0].should == [t[:baz], {}]
+ t[1].should == [t[:bar], {}]
end
it "allows tasks to be copied" do

0 comments on commit 45ade5b

Please sign in to comment.