Permalink
Browse files

Refactors setting and getting backend; the object itself is returned

  • Loading branch information...
alindeman committed Mar 5, 2012
1 parent 0a33708 commit 3e8a3e6699e3ada3673b9d037b3064afcdb47356
Showing with 17 additions and 7 deletions.
  1. +16 −6 lib/zonebie.rb
  2. +1 −1 spec/lib/zonebie_spec.rb
View
@@ -7,15 +7,22 @@ def backend
self.backend = :activesupport
end
- @backend.name
+ @backend
end
- def backend=(backend_name)
- if backend = @backends.detect { |b| b.name == backend_name }
- @backend = backend
+ def backend=(backend)
+ case backend
+ when Symbol
+ @backend = @backends.detect { |b| b.name == backend }
else
- raise ArgumentError, "Unsupported backend: #{backend_name}"
+ @backend = backend
end
+
+ unless @backend
+ raise ArgumentError, "Unsupported backend: #{backend}"
+ end
+
+ @backend
end
def add_backend(backend)
@@ -24,7 +31,10 @@ def add_backend(backend)
end
def set_random_timezone
- zones = @backend.zones
+ zones = backend.zones
+ zone = zones[rand(zones.length)]
+
+ $stdout.puts("[Zonebie] Setting timezone to \"#{zone}\"")
@backend.zone = zones[rand(zones.length)]
end
end
View
@@ -3,7 +3,7 @@
describe Zonebie do
describe "#backend" do
it "defaults to the activesupport backend in the presence of activesupport" do
- Zonebie.backend.should == :activesupport
+ Zonebie.backend.name.should == :activesupport
end
pending "allows setting the backend to tzinfo"

0 comments on commit 3e8a3e6

Please sign in to comment.