Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
implement dynamic destinations
Browse files Browse the repository at this point in the history
  • Loading branch information
jfredett committed Nov 14, 2011
1 parent 6050f31 commit 8dcc7cc
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 16 deletions.
6 changes: 5 additions & 1 deletion lib/sortah/cleanroom.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ def run!(component)
end

def send_to(dest)
@pointer = @__context__.routers[dest] || @__context__.destinations[dest]
@pointer = if dest.is_a? Hash
Destination.dynamic(dest[:dynamic])
else
@__context__.routers[dest] || @__context__.destinations[dest]
end
throw :finished_execution
end

Expand Down
4 changes: 4 additions & 0 deletions lib/sortah/components/destination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def [](key)
class Destination
attr_reader :name, :path

def self.dynamic(path)
Destination.new(nil, path)
end

def initialize(name, path)
@name = name
@path = if path.class == Hash then path[:abs] else path end
Expand Down
35 changes: 20 additions & 15 deletions spec/semantic_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,16 @@ def basic_sortah_definition
end

describe "#sort" do
it "should return an object which responds to #destination" do
basic_sortah_definition
sortah.sort(@email).should respond_to :destination
end

it "should return an object which responds to #metadata" do
basic_sortah_definition
sortah.sort(@email).should respond_to :metadata
end

it "should sort emails based on the sortah definitions" do
basic_sortah_definition
sortah.sort(@email).destination.should == "foo/"
sortah.sort(@reply_email).destination.should == "bar/"
context "when using sortah#sort, " do
subject { basic_sortah_definition; sortah.sort(@email) }
it { should respond_to :destination }
it { should respond_to :metadata }

subject { basic_sortah_definition; sortah }
it "should sort emails based on the sortah definitions" do
subject.sort(@email).destination.should == "foo/"
subject.sort(@reply_email).destination.should == "bar/"
end
end

it "should defer to a second router if it is sent to one" do
Expand Down Expand Up @@ -341,7 +337,16 @@ def basic_sortah_definition
end
end
sortah.sort(@email).full_destination.should == "/tmp/foo/"

end

it "should return the correct path when using a dynamic destination" do
sortah do
maildir '/tmp/'
router do
send_to :dynamic => "foo.bar.baz"
end
end
sortah.sort(@email).full_destination.should == "/tmp/foo.bar.baz"
end
end

Expand Down

0 comments on commit 8dcc7cc

Please sign in to comment.