Skip to content

Commit

Permalink
Reorder methods so all the config methods are together again
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisk committed Jan 1, 2010
1 parent 6213abf commit d725797
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions lib/samuel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Samuel

VERSION = "0.2.1"

attr_writer :config, :logger
attr_writer :logger, :config

def logger
@logger = nil if !defined?(@logger)
Expand All @@ -30,26 +30,6 @@ def config
Thread.current[:__samuel_config] ? Thread.current[:__samuel_config] : @config
end

def log_request_and_response(http, request, response, time_started, time_ended)
log_entry_class = case http.class.to_s
when "Net::HTTP" then LogEntries::NetHttp
when "HTTPClient" then LogEntries::HttpClient
else raise NotImplementedError
end
log_entry = log_entry_class.new(http, request, response, time_started, time_ended)
log_entry.log!
end

def record_request(http, request, time_requested)
@requests ||= []
@requests.push({:request => request, :time_requested => time_requested})
end

def record_response(http, request, response, time_responded)
time_requested = @requests.detect { |r| r[:request] == request }[:time_requested]
Samuel.log_request_and_response(http, request, response, time_requested, time_responded)
end

def with_config(options = {})
original_config = config.dup
nested = !Thread.current[:__samuel_config].nil?
Expand All @@ -64,6 +44,26 @@ def reset_config
@config = {:label => nil, :labels => {"" => "HTTP"}, :filtered_params => []}
end

def record_request(http, request, time_requested)
@requests ||= []
@requests.push({:request => request, :time_requested => time_requested})
end

def record_response(http, request, response, time_responded)
time_requested = @requests.detect { |r| r[:request] == request }[:time_requested]
Samuel.log_request_and_response(http, request, response, time_requested, time_responded)
end

def log_request_and_response(http, request, response, time_started, time_ended)
log_entry_class = case http.class.to_s
when "Net::HTTP" then LogEntries::NetHttp
when "HTTPClient" then LogEntries::HttpClient
else raise NotImplementedError
end
log_entry = log_entry_class.new(http, request, response, time_started, time_ended)
log_entry.log!
end

def load_drivers
loaded = { :net_http => defined?(Net::HTTP),
:http_client => defined?(HTTPClient) }
Expand Down

0 comments on commit d725797

Please sign in to comment.