lib/hwacha.rb in hwacha-0.1.0 vs lib/hwacha.rb in hwacha-0.2.0
- old
+ new
@@ -1,10 +1,21 @@
require "hwacha/version"
+require "hwacha/config"
require "typhoeus"
class Hwacha
+ attr_reader :max_concurrent_requests
+
def initialize(max_concurrent_requests=20)
- @max_concurrent_requests = max_concurrent_requests
+ config = Hwacha::Config.new
+
+ # support the simple legacy API
+ config.max_concurrent_requests = max_concurrent_requests
+
+ # the nice configuration object API
+ yield config if block_given?
+
+ @max_concurrent_requests = config.max_concurrent_requests
end
def check(urls)
hydra = Typhoeus::Hydra.new(:max_concurrency => @max_concurrent_requests)