Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

implement dynamic destinations

  • Loading branch information...
commit 8dcc7cc28afaa73423fd93c3ff7c9b0040eb4203 1 parent 6050f31
@jfredett authored
View
6 lib/sortah/cleanroom.rb
@@ -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
View
4 lib/sortah/components/destination.rb
@@ -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
View
35 spec/semantic_spec.rb
@@ -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
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.