Browse files

a cleaner solution for multiple urls

  • Loading branch information...
1 parent d578c97 commit 7fba09c631d573a97497f279f63843479ddb4381 @cover committed Dec 17, 2011
Showing with 8 additions and 8 deletions.
  1. +5 −5 lib/tire/configuration.rb
  2. +3 −3 test/unit/configuration_test.rb
View
10 lib/tire/configuration.rb
@@ -2,13 +2,13 @@ module Tire
class Configuration
- def self.urls(values=nil)
- @urls = (values && values.any? ? values.map{|value| value.to_s.gsub(%r|/*$|, '')} : nil) || @urls || ["http://localhost:9200"]
+ def self.urls
+ @urls || ["http://localhost:9200"]
end
- def self.url(value=nil)
- urls([value])
- @urls.respond_to?(:sample) ? @urls.sample : @urls.choice
+ def self.url(*values)
+ @urls = values.map{|value| value.to_s.gsub(%r|/*$|, '')} if values.any?
+ urls.respond_to?(:sample) ? urls.sample : urls.choice
end
def self.client(klass=nil)
View
6 test/unit/configuration_test.rb
@@ -33,17 +33,17 @@ def teardown
end
should "allow setting more URLS" do
- assert_nothing_raised { Configuration.urls ['http://example1.com', 'http://example2.com'] }
+ assert_nothing_raised { Configuration.url 'http://example1.com', 'http://example2.com' }
assert_equal ['http://example1.com', 'http://example2.com'], Configuration.urls
end
should "strip trailing slash from all the URLS" do
- assert_nothing_raised { Configuration.urls ['http://slash1.com:9200/', 'http://slash2.com:9200/'] }
+ assert_nothing_raised { Configuration.url 'http://slash1.com:9200/', 'http://slash2.com:9200/' }
assert_equal ['http://slash1.com:9200', 'http://slash2.com:9200'], Configuration.urls
end
should "retrieve a random URL from the ones available" do
- assert_nothing_raised { Configuration.urls ['http://example1.com', 'http://example2.com'] }
+ assert_nothing_raised { Configuration.url 'http://example1.com', 'http://example2.com' }
url = Configuration.url
begin
assert_equal 'http://example1.com', url

0 comments on commit 7fba09c

Please sign in to comment.