Permalink
Browse files

Store the hash of settings passed to the Client.

  • Loading branch information...
1 parent 17ecc41 commit 961bfc3a4efc81d045b9ef8886d12b45ae380f8c @weppos committed Dec 20, 2010
Showing with 34 additions and 18 deletions.
  1. +12 −6 lib/whois/client.rb
  2. +22 −12 spec/whois/client_spec.rb
View
@@ -29,14 +29,17 @@ class Client
# @return [Fixnum, nil] The current timeout value, expressed in seconds.
attr_accessor :timeout
+ # @return [Hash] The current client settings.
+ attr_accessor :settings
+
# Initializes a new <tt>Whois::Client</tt> with <tt>settings</tt>.
#
# If <tt>block</tt> is given, yields <tt>self</tt>.
#
- # @param [Hash] options Hash of options.
+ # @param [Hash] settings Hash of settings to customize the client behavior.
# @option settings [Fixnum, nil] :timeout (DEFAULT_TIMEOUT)
- # The script timeout, expressed in seconds.
+ # The timeout for a WHOIS query, expressed in seconds.
#
# @yield [self]
#
@@ -55,15 +58,18 @@ class Client
#
def initialize(settings = {}, &block)
settings = settings.dup
- self.timeout = settings.key?(:timeout) ? settings.delete(:timeout) : DEFAULT_TIMEOUT
+
+ self.timeout = settings.key?(:timeout) ? settings.delete(:timeout) : DEFAULT_TIMEOUT
+ self.settings = settings
+
yield(self) if block_given?
end
- # Queries the right WHOIS server for <tt>qstring</tt> and returns
- # the response from the server.
+ # Queries the right WHOIS server for <tt>object</tt>
+ # and returns the response from the server.
#
- # @param [String] object The string to be sent as query parameter.
+ # @param [#to_s] object The string to be sent as query parameter.
# @return [Whois::Answer] The answer object containing the WHOIS response.
#
# @raise [Timeout::Error]
View
@@ -2,36 +2,46 @@
describe Whois::Client do
- context ".new" do
- it "creates a new instance" do
- client = klass.new
- client.should be_instance_of(klass)
+ context "#initialize" do
+ it "accepts a zero parameters" do
+ lambda { klass.new }.should_not raise_error
+ end
+
+ it "accepts a settings parameter" do
+ lambda { klass.new({ :foo => "bar" }) }.should_not raise_error
end
- it "accepts a timeout option with a value in seconds" do
+
+ it "accepts a timeout setting with a value in seconds" do
client = klass.new(:timeout => 100)
client.timeout.should == 100
end
- it "accepts a timeout option with a nil value" do
+ it "accepts a timeout setting with a nil value" do
client = klass.new(:timeout => nil)
client.timeout.should be_nil
end
- it "defaults timeout option to DEFAULT_TIMEOUT" do
- client = klass.new
- client.timeout.should == klass::DEFAULT_TIMEOUT
- end
-
it "accepts a block" do
klass.new do |client|
client.should be_instance_of(klass)
end
end
+
+
+ it "defaults timeout setting to DEFAULT_TIMEOUT" do
+ client = klass.new
+ client.timeout.should == klass::DEFAULT_TIMEOUT
+ end
+
+ it "sets settings to given argument, except timeout" do
+ client = klass.new(:timeout => nil, :foo => "bar")
+ client.settings.should == { :foo => "bar" }
+ end
end
context "#query" do
- it "coerces qstring to string" do
+ it "coerces the argument to string" do
server = Object.new
# I can't use the String because Array#to_s behaves differently
# on Ruby 1.8.7 and Ruby 1.9.1

0 comments on commit 961bfc3

Please sign in to comment.